@lvce-editor/title-bar-worker 4.25.0 → 4.25.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/titleBarWorkerMain.js +299 -270
- package/package.json +1 -1
|
@@ -54,6 +54,61 @@ class VError extends Error {
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
class AssertionError extends Error {
|
|
58
|
+
constructor(message) {
|
|
59
|
+
super(message);
|
|
60
|
+
this.name = 'AssertionError';
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const Object$1 = 1;
|
|
64
|
+
const Number$1 = 2;
|
|
65
|
+
const Array$1 = 3;
|
|
66
|
+
const String$1 = 4;
|
|
67
|
+
const Boolean$1 = 5;
|
|
68
|
+
const Function = 6;
|
|
69
|
+
const Null = 7;
|
|
70
|
+
const Unknown$1 = 8;
|
|
71
|
+
const getType = value => {
|
|
72
|
+
switch (typeof value) {
|
|
73
|
+
case 'number':
|
|
74
|
+
return Number$1;
|
|
75
|
+
case 'function':
|
|
76
|
+
return Function;
|
|
77
|
+
case 'string':
|
|
78
|
+
return String$1;
|
|
79
|
+
case 'object':
|
|
80
|
+
if (value === null) {
|
|
81
|
+
return Null;
|
|
82
|
+
}
|
|
83
|
+
if (Array.isArray(value)) {
|
|
84
|
+
return Array$1;
|
|
85
|
+
}
|
|
86
|
+
return Object$1;
|
|
87
|
+
case 'boolean':
|
|
88
|
+
return Boolean$1;
|
|
89
|
+
default:
|
|
90
|
+
return Unknown$1;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
const object = value => {
|
|
94
|
+
const type = getType(value);
|
|
95
|
+
if (type !== Object$1) {
|
|
96
|
+
throw new AssertionError('expected value to be of type object');
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
const number = value => {
|
|
100
|
+
const type = getType(value);
|
|
101
|
+
if (type !== Number$1) {
|
|
102
|
+
throw new AssertionError('expected value to be of type number');
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
const array = value => {
|
|
106
|
+
const type = getType(value);
|
|
107
|
+
if (type !== Array$1) {
|
|
108
|
+
throw new AssertionError('expected value to be of type array');
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
57
112
|
const isMessagePort = value => {
|
|
58
113
|
return value && value instanceof MessagePort;
|
|
59
114
|
};
|
|
@@ -602,6 +657,9 @@ const restoreExistingError = (error, currentStack) => {
|
|
|
602
657
|
};
|
|
603
658
|
const restoreMethodNotFoundError = (error, currentStack) => {
|
|
604
659
|
const restoredError = new JsonRpcError(error.message);
|
|
660
|
+
Object.assign(restoredError, {
|
|
661
|
+
code: error.code
|
|
662
|
+
});
|
|
605
663
|
const parentStack = getParentStack(error);
|
|
606
664
|
setStack(restoredError, `${parentStack}${NewLine}${currentStack}`);
|
|
607
665
|
return restoredError;
|
|
@@ -621,9 +679,13 @@ const applyDataProperties = (restoredError, error) => {
|
|
|
621
679
|
// @ts-ignore
|
|
622
680
|
restoredError.codeFrame = error.data.codeFrame;
|
|
623
681
|
}
|
|
624
|
-
if (error.data.code) {
|
|
682
|
+
if (typeof error.data.code === 'string' || typeof error.data.code === 'number') {
|
|
625
683
|
// @ts-ignore
|
|
626
|
-
restoredError
|
|
684
|
+
Object.defineProperty(restoredError, 'code', {
|
|
685
|
+
configurable: true,
|
|
686
|
+
value: error.data.code,
|
|
687
|
+
writable: true
|
|
688
|
+
});
|
|
627
689
|
}
|
|
628
690
|
if (error.data.type) {
|
|
629
691
|
// @ts-ignore
|
|
@@ -644,7 +706,14 @@ const applyDirectProperties = (restoredError, error) => {
|
|
|
644
706
|
}
|
|
645
707
|
};
|
|
646
708
|
const restoreMessageError = (error, _currentStack) => {
|
|
647
|
-
const restoredError = constructError(error.message, error.type, error.name);
|
|
709
|
+
const restoredError = constructError(error.message, error.type || error.data?.type, error.name);
|
|
710
|
+
if (typeof error.code === 'string' || typeof error.code === 'number') {
|
|
711
|
+
Object.defineProperty(restoredError, 'code', {
|
|
712
|
+
configurable: true,
|
|
713
|
+
value: error.code,
|
|
714
|
+
writable: true
|
|
715
|
+
});
|
|
716
|
+
}
|
|
648
717
|
if (error.data) {
|
|
649
718
|
applyDataProperties(restoredError, error);
|
|
650
719
|
} else {
|
|
@@ -723,9 +792,9 @@ const getErrorProperty = (error, prettyError) => {
|
|
|
723
792
|
return {
|
|
724
793
|
code: Custom,
|
|
725
794
|
data: {
|
|
726
|
-
code: prettyError.code,
|
|
795
|
+
code: prettyError.code ?? error?.code,
|
|
727
796
|
codeFrame: prettyError.codeFrame,
|
|
728
|
-
name: prettyError.name,
|
|
797
|
+
name: prettyError.name ?? error?.name,
|
|
729
798
|
stack: getStack(prettyError),
|
|
730
799
|
type: getErrorType(prettyError)
|
|
731
800
|
},
|
|
@@ -760,7 +829,12 @@ const getErrorResponseSimple = (id, error) => {
|
|
|
760
829
|
return {
|
|
761
830
|
error: {
|
|
762
831
|
code: Custom,
|
|
763
|
-
data: error
|
|
832
|
+
data: error instanceof Error ? {
|
|
833
|
+
...error,
|
|
834
|
+
code: 'code' in error ? error.code : undefined,
|
|
835
|
+
stack: error.stack,
|
|
836
|
+
type: error.name
|
|
837
|
+
} : error,
|
|
764
838
|
// @ts-ignore
|
|
765
839
|
message: error.message
|
|
766
840
|
},
|
|
@@ -1370,7 +1444,7 @@ const Backslash$2 = 91;
|
|
|
1370
1444
|
const Star$1 = 131;
|
|
1371
1445
|
const Plus$1 = 132;
|
|
1372
1446
|
|
|
1373
|
-
const Unknown
|
|
1447
|
+
const Unknown = 'Unknown';
|
|
1374
1448
|
const Backspace = 'Backspace';
|
|
1375
1449
|
const Tab = 'Tab';
|
|
1376
1450
|
const Enter = 'Enter';
|
|
@@ -1503,7 +1577,7 @@ const keyCodeStringMap = {
|
|
|
1503
1577
|
[UpArrow$1]: UpArrow
|
|
1504
1578
|
};
|
|
1505
1579
|
const getKeyCodeString = keyCode => {
|
|
1506
|
-
return keyCodeStringMap[keyCode] || Unknown
|
|
1580
|
+
return keyCodeStringMap[keyCode] || Unknown;
|
|
1507
1581
|
};
|
|
1508
1582
|
|
|
1509
1583
|
const CtrlCmd = 1 << 11 >>> 0;
|
|
@@ -1557,61 +1631,6 @@ const {
|
|
|
1557
1631
|
set: set$3
|
|
1558
1632
|
} = create$2(RendererProcess);
|
|
1559
1633
|
|
|
1560
|
-
class AssertionError extends Error {
|
|
1561
|
-
constructor(message) {
|
|
1562
|
-
super(message);
|
|
1563
|
-
this.name = 'AssertionError';
|
|
1564
|
-
}
|
|
1565
|
-
}
|
|
1566
|
-
const Object$1 = 1;
|
|
1567
|
-
const Number$1 = 2;
|
|
1568
|
-
const Array$1 = 3;
|
|
1569
|
-
const String$1 = 4;
|
|
1570
|
-
const Boolean$1 = 5;
|
|
1571
|
-
const Function = 6;
|
|
1572
|
-
const Null = 7;
|
|
1573
|
-
const Unknown = 8;
|
|
1574
|
-
const getType = value => {
|
|
1575
|
-
switch (typeof value) {
|
|
1576
|
-
case 'number':
|
|
1577
|
-
return Number$1;
|
|
1578
|
-
case 'function':
|
|
1579
|
-
return Function;
|
|
1580
|
-
case 'string':
|
|
1581
|
-
return String$1;
|
|
1582
|
-
case 'object':
|
|
1583
|
-
if (value === null) {
|
|
1584
|
-
return Null;
|
|
1585
|
-
}
|
|
1586
|
-
if (Array.isArray(value)) {
|
|
1587
|
-
return Array$1;
|
|
1588
|
-
}
|
|
1589
|
-
return Object$1;
|
|
1590
|
-
case 'boolean':
|
|
1591
|
-
return Boolean$1;
|
|
1592
|
-
default:
|
|
1593
|
-
return Unknown;
|
|
1594
|
-
}
|
|
1595
|
-
};
|
|
1596
|
-
const object = value => {
|
|
1597
|
-
const type = getType(value);
|
|
1598
|
-
if (type !== Object$1) {
|
|
1599
|
-
throw new AssertionError('expected value to be of type object');
|
|
1600
|
-
}
|
|
1601
|
-
};
|
|
1602
|
-
const number = value => {
|
|
1603
|
-
const type = getType(value);
|
|
1604
|
-
if (type !== Number$1) {
|
|
1605
|
-
throw new AssertionError('expected value to be of type number');
|
|
1606
|
-
}
|
|
1607
|
-
};
|
|
1608
|
-
const array = value => {
|
|
1609
|
-
const type = getType(value);
|
|
1610
|
-
if (type !== Array$1) {
|
|
1611
|
-
throw new AssertionError('expected value to be of type array');
|
|
1612
|
-
}
|
|
1613
|
-
};
|
|
1614
|
-
|
|
1615
1634
|
const {
|
|
1616
1635
|
invoke: invoke$1,
|
|
1617
1636
|
invokeAndTransfer,
|
|
@@ -1631,9 +1650,6 @@ const sendMessagePortToTextMeasurementWorker = async port => {
|
|
|
1631
1650
|
const minimizeWindow = async () => {
|
|
1632
1651
|
return invoke$1('ElectronWindow.minimize');
|
|
1633
1652
|
};
|
|
1634
|
-
const maximizeWindow = async () => {
|
|
1635
|
-
return invoke$1('ElectronWindow.maximize');
|
|
1636
|
-
};
|
|
1637
1653
|
const closeWindow = async () => {
|
|
1638
1654
|
return invoke$1('ElectronWindow.close');
|
|
1639
1655
|
};
|
|
@@ -2063,7 +2079,7 @@ const help = () => {
|
|
|
2063
2079
|
const minimize$1 = () => {
|
|
2064
2080
|
return i18nString(Minimize);
|
|
2065
2081
|
};
|
|
2066
|
-
const maximize
|
|
2082
|
+
const maximize = () => {
|
|
2067
2083
|
return i18nString(Maximize);
|
|
2068
2084
|
};
|
|
2069
2085
|
const close$1 = () => {
|
|
@@ -2123,7 +2139,7 @@ const getTitleBarButtonsElectron = (controlsOverlayEnabled, titleBarStyleCustom)
|
|
|
2123
2139
|
}, {
|
|
2124
2140
|
icon: 'Maximize',
|
|
2125
2141
|
id: 'ToggleMaximize',
|
|
2126
|
-
label: maximize
|
|
2142
|
+
label: maximize(),
|
|
2127
2143
|
onClick: HandleClickToggleMaximize
|
|
2128
2144
|
}, {
|
|
2129
2145
|
icon: 'ChromeClose',
|
|
@@ -2161,8 +2177,9 @@ const {
|
|
|
2161
2177
|
getCommandIds,
|
|
2162
2178
|
registerCommands,
|
|
2163
2179
|
set: set$1,
|
|
2164
|
-
wrapCommand,
|
|
2165
|
-
wrapGetter
|
|
2180
|
+
wrapCommand: wrapNotification,
|
|
2181
|
+
wrapGetter,
|
|
2182
|
+
wrapSerialCommand: wrapCommand
|
|
2166
2183
|
} = create$1();
|
|
2167
2184
|
|
|
2168
2185
|
const create3 = (id, uri, x, y, width, height, platform, controlsOverlayEnabled, titleBarStyleCustom, assetDir) => {
|
|
@@ -2651,7 +2668,7 @@ const getMenuEntries$b = async (platform, autoSave$1, hasActiveTextEditor = fals
|
|
|
2651
2668
|
const saveFlags = getSaveFlags(hasActiveTextEditor);
|
|
2652
2669
|
const entries = [{
|
|
2653
2670
|
command: 'Main.newFile',
|
|
2654
|
-
flags:
|
|
2671
|
+
flags: RestoreEditorFocus,
|
|
2655
2672
|
id: 'newFile',
|
|
2656
2673
|
label: newFile()
|
|
2657
2674
|
}, {
|
|
@@ -3766,8 +3783,8 @@ const getKeyBindings = () => {
|
|
|
3766
3783
|
}];
|
|
3767
3784
|
};
|
|
3768
3785
|
|
|
3769
|
-
const
|
|
3770
|
-
await
|
|
3786
|
+
const toggleMaximize = async () => {
|
|
3787
|
+
await invoke$1('ElectronWindow.toggleMaximize');
|
|
3771
3788
|
};
|
|
3772
3789
|
const minimize = async () => {
|
|
3773
3790
|
await minimizeWindow();
|
|
@@ -3787,8 +3804,7 @@ const handleClickMinimize = async state => {
|
|
|
3787
3804
|
};
|
|
3788
3805
|
|
|
3789
3806
|
const handleClickToggleMaximize = async state => {
|
|
3790
|
-
|
|
3791
|
-
await fn();
|
|
3807
|
+
await toggleMaximize();
|
|
3792
3808
|
return state;
|
|
3793
3809
|
};
|
|
3794
3810
|
|
|
@@ -3805,136 +3821,6 @@ const handleClick$1 = async (state, buttonName) => {
|
|
|
3805
3821
|
return state;
|
|
3806
3822
|
};
|
|
3807
3823
|
|
|
3808
|
-
const commandCenterItems = [{
|
|
3809
|
-
command: 'QuickPick.showFile',
|
|
3810
|
-
label: 'Go to File'
|
|
3811
|
-
}, {
|
|
3812
|
-
command: 'QuickPick.showCommands',
|
|
3813
|
-
label: 'Show and Run Commands'
|
|
3814
|
-
}, {
|
|
3815
|
-
args: ['Search'],
|
|
3816
|
-
command: 'Layout.openSideBarViewlet',
|
|
3817
|
-
label: 'Search for Text'
|
|
3818
|
-
}, {
|
|
3819
|
-
args: ['symbol'],
|
|
3820
|
-
command: 'QuickPick.show',
|
|
3821
|
-
label: 'Go to Symbol in Editor'
|
|
3822
|
-
}, {
|
|
3823
|
-
args: ['Run And Debug'],
|
|
3824
|
-
command: 'Layout.openSideBarViewlet',
|
|
3825
|
-
label: 'Start Debugging'
|
|
3826
|
-
}, {
|
|
3827
|
-
command: 'QuickPick.showCommands',
|
|
3828
|
-
label: 'Run Task'
|
|
3829
|
-
}, {
|
|
3830
|
-
command: 'QuickPick.showEverything',
|
|
3831
|
-
label: 'More'
|
|
3832
|
-
}];
|
|
3833
|
-
const handleCommandCenterClick = async state => {
|
|
3834
|
-
await invoke$1('QuickPick.show', 'custom', commandCenterItems, undefined, {
|
|
3835
|
-
executeItemCommand: true,
|
|
3836
|
-
mode: 'quickPick',
|
|
3837
|
-
placeholder: 'Search files by name (append : to go to line or @ to go to symbol)',
|
|
3838
|
-
waitUntil: 'visible'
|
|
3839
|
-
});
|
|
3840
|
-
return state;
|
|
3841
|
-
};
|
|
3842
|
-
|
|
3843
|
-
const handleCommandCenterKeyDown = async (state, key) => {
|
|
3844
|
-
if (key !== 'Enter' && key !== ' ' && key !== 'Space') {
|
|
3845
|
-
return state;
|
|
3846
|
-
}
|
|
3847
|
-
return handleCommandCenterClick(state);
|
|
3848
|
-
};
|
|
3849
|
-
|
|
3850
|
-
const show2 = async (uid, menuId, x, y, args) => {
|
|
3851
|
-
await showContextMenu2(uid, menuId, x, y, args);
|
|
3852
|
-
};
|
|
3853
|
-
|
|
3854
|
-
const handleContextMenu = async (state, button, eventX, eventY) => {
|
|
3855
|
-
const {
|
|
3856
|
-
uid
|
|
3857
|
-
} = state;
|
|
3858
|
-
await show2(uid, MenuIdTitleBarContextMenu, eventX, eventY, {
|
|
3859
|
-
menuId: MenuIdTitleBarContextMenu
|
|
3860
|
-
});
|
|
3861
|
-
return state;
|
|
3862
|
-
};
|
|
3863
|
-
|
|
3864
|
-
const handleElectronMenuClick = async (state, label) => {
|
|
3865
|
-
const {
|
|
3866
|
-
commandMap
|
|
3867
|
-
} = state;
|
|
3868
|
-
const commandPair = commandMap[label];
|
|
3869
|
-
if (!commandPair) {
|
|
3870
|
-
throw new Error(`no command found for ${label}`);
|
|
3871
|
-
}
|
|
3872
|
-
const {
|
|
3873
|
-
args = [],
|
|
3874
|
-
command
|
|
3875
|
-
} = commandPair;
|
|
3876
|
-
await invoke$1(command, ...args);
|
|
3877
|
-
return state;
|
|
3878
|
-
};
|
|
3879
|
-
|
|
3880
|
-
const state = {
|
|
3881
|
-
connected: false
|
|
3882
|
-
};
|
|
3883
|
-
const isConnected = () => {
|
|
3884
|
-
const {
|
|
3885
|
-
connected
|
|
3886
|
-
} = state;
|
|
3887
|
-
return connected;
|
|
3888
|
-
};
|
|
3889
|
-
const invoke = (method, ...params) => {
|
|
3890
|
-
return invoke$2(method, ...params);
|
|
3891
|
-
};
|
|
3892
|
-
const set = rpc => {
|
|
3893
|
-
set$3(rpc);
|
|
3894
|
-
state.connected = true;
|
|
3895
|
-
};
|
|
3896
|
-
|
|
3897
|
-
const commandQueues = new Map();
|
|
3898
|
-
const handleMessagePort = async (port, viewletCommandMap, setAsRendererProcess = true) => {
|
|
3899
|
-
const executeViewletCommand = async (uid, command, ...args) => {
|
|
3900
|
-
const fn = viewletCommandMap[`TitleBar.${command}`];
|
|
3901
|
-
if (typeof fn !== 'function') {
|
|
3902
|
-
throw new TypeError(`Viewlet command not found: ${command}`);
|
|
3903
|
-
}
|
|
3904
|
-
const previous = commandQueues.get(uid);
|
|
3905
|
-
const {
|
|
3906
|
-
promise: next,
|
|
3907
|
-
resolve
|
|
3908
|
-
} = Promise.withResolvers();
|
|
3909
|
-
commandQueues.set(uid, next);
|
|
3910
|
-
if (previous) {
|
|
3911
|
-
await previous;
|
|
3912
|
-
}
|
|
3913
|
-
try {
|
|
3914
|
-
await fn(uid, ...args);
|
|
3915
|
-
await invoke$1('Viewlet.requestRender', uid);
|
|
3916
|
-
} finally {
|
|
3917
|
-
resolve();
|
|
3918
|
-
if (commandQueues.get(uid) === next) {
|
|
3919
|
-
commandQueues.delete(uid);
|
|
3920
|
-
}
|
|
3921
|
-
}
|
|
3922
|
-
};
|
|
3923
|
-
const rpc = await create$6({
|
|
3924
|
-
commandMap: {
|
|
3925
|
-
'Viewlet.executeViewletCommand': executeViewletCommand
|
|
3926
|
-
},
|
|
3927
|
-
messagePort: port
|
|
3928
|
-
});
|
|
3929
|
-
if (setAsRendererProcess) {
|
|
3930
|
-
set(rpc);
|
|
3931
|
-
}
|
|
3932
|
-
};
|
|
3933
|
-
|
|
3934
|
-
const getMenuOffset = (x, clientX, iconWidth) => {
|
|
3935
|
-
return clientX - x - iconWidth;
|
|
3936
|
-
};
|
|
3937
|
-
|
|
3938
3824
|
const getNavigableTitleBarEntries = state => {
|
|
3939
3825
|
const {
|
|
3940
3826
|
focusedIndex,
|
|
@@ -3945,17 +3831,30 @@ const getNavigableTitleBarEntries = state => {
|
|
|
3945
3831
|
return getVisibleTitleBarEntries(titleBarEntries, width, focusedIndex, isMenuOpen);
|
|
3946
3832
|
};
|
|
3947
3833
|
|
|
3948
|
-
const
|
|
3949
|
-
|
|
3950
|
-
|
|
3951
|
-
|
|
3952
|
-
|
|
3953
|
-
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
|
|
3834
|
+
const LeftClick = 0;
|
|
3835
|
+
|
|
3836
|
+
const closeMenu = (state, keepFocus) => {
|
|
3837
|
+
const {
|
|
3838
|
+
focused,
|
|
3839
|
+
focusedIndex,
|
|
3840
|
+
isMenuOpen,
|
|
3841
|
+
menus
|
|
3842
|
+
} = state;
|
|
3843
|
+
// TODO send to renderer process
|
|
3844
|
+
// 1. close menu
|
|
3845
|
+
// 2. focus top level entry
|
|
3846
|
+
const newFocused = keepFocus ? focused : false;
|
|
3847
|
+
const newFocusedIndex = keepFocus ? focusedIndex : -1;
|
|
3848
|
+
if (!isMenuOpen && menus.length === 0 && focused === newFocused && focusedIndex === newFocusedIndex) {
|
|
3849
|
+
return state;
|
|
3957
3850
|
}
|
|
3958
|
-
return
|
|
3851
|
+
return {
|
|
3852
|
+
...state,
|
|
3853
|
+
focused: newFocused,
|
|
3854
|
+
focusedIndex: newFocusedIndex,
|
|
3855
|
+
isMenuOpen: false,
|
|
3856
|
+
menus: []
|
|
3857
|
+
};
|
|
3959
3858
|
};
|
|
3960
3859
|
|
|
3961
3860
|
const toCommandInfo = entry => {
|
|
@@ -4145,6 +4044,180 @@ const openMenuAtIndex = async (state, index, shouldBeFocused) => {
|
|
|
4145
4044
|
};
|
|
4146
4045
|
};
|
|
4147
4046
|
|
|
4047
|
+
const toggleIndex = async (state, index) => {
|
|
4048
|
+
const {
|
|
4049
|
+
focusedIndex,
|
|
4050
|
+
isMenuOpen
|
|
4051
|
+
} = state;
|
|
4052
|
+
if (isMenuOpen && focusedIndex === index) {
|
|
4053
|
+
return closeMenu(state, /* keepFocus */true);
|
|
4054
|
+
}
|
|
4055
|
+
return openMenuAtIndex(state, index, /* focus */false);
|
|
4056
|
+
};
|
|
4057
|
+
|
|
4058
|
+
const handleClick = async (state, button, index) => {
|
|
4059
|
+
if (button !== LeftClick) {
|
|
4060
|
+
return state;
|
|
4061
|
+
}
|
|
4062
|
+
if (index === -1) {
|
|
4063
|
+
return state;
|
|
4064
|
+
}
|
|
4065
|
+
const newState = await toggleIndex(state, index);
|
|
4066
|
+
return {
|
|
4067
|
+
...newState,
|
|
4068
|
+
focused: true
|
|
4069
|
+
};
|
|
4070
|
+
};
|
|
4071
|
+
|
|
4072
|
+
const handleClickByName = async (state, button, name) => {
|
|
4073
|
+
const entries = getNavigableTitleBarEntries(state);
|
|
4074
|
+
const index = entries.findIndex(entry => entry.label === name);
|
|
4075
|
+
return handleClick(state, button, index);
|
|
4076
|
+
};
|
|
4077
|
+
|
|
4078
|
+
const commandCenterItems = [{
|
|
4079
|
+
command: 'QuickPick.showFile',
|
|
4080
|
+
label: 'Go to File'
|
|
4081
|
+
}, {
|
|
4082
|
+
command: 'QuickPick.showCommands',
|
|
4083
|
+
label: 'Show and Run Commands'
|
|
4084
|
+
}, {
|
|
4085
|
+
args: ['Search'],
|
|
4086
|
+
command: 'Layout.openSideBarViewlet',
|
|
4087
|
+
label: 'Search for Text'
|
|
4088
|
+
}, {
|
|
4089
|
+
args: ['symbol'],
|
|
4090
|
+
command: 'QuickPick.show',
|
|
4091
|
+
label: 'Go to Symbol in Editor'
|
|
4092
|
+
}, {
|
|
4093
|
+
args: ['Run And Debug'],
|
|
4094
|
+
command: 'Layout.openSideBarViewlet',
|
|
4095
|
+
label: 'Start Debugging'
|
|
4096
|
+
}, {
|
|
4097
|
+
command: 'QuickPick.showCommands',
|
|
4098
|
+
label: 'Run Task'
|
|
4099
|
+
}, {
|
|
4100
|
+
command: 'QuickPick.showEverything',
|
|
4101
|
+
label: 'More'
|
|
4102
|
+
}];
|
|
4103
|
+
const handleCommandCenterClick = async state => {
|
|
4104
|
+
await invoke$1('QuickPick.show', 'custom', commandCenterItems, undefined, {
|
|
4105
|
+
executeItemCommand: true,
|
|
4106
|
+
mode: 'quickPick',
|
|
4107
|
+
placeholder: 'Search files by name (append : to go to line or @ to go to symbol)',
|
|
4108
|
+
waitUntil: 'visible'
|
|
4109
|
+
});
|
|
4110
|
+
return state;
|
|
4111
|
+
};
|
|
4112
|
+
|
|
4113
|
+
const handleCommandCenterKeyDown = async (state, key) => {
|
|
4114
|
+
if (key !== 'Enter' && key !== ' ' && key !== 'Space') {
|
|
4115
|
+
return state;
|
|
4116
|
+
}
|
|
4117
|
+
return handleCommandCenterClick(state);
|
|
4118
|
+
};
|
|
4119
|
+
|
|
4120
|
+
const show2 = async (uid, menuId, x, y, args) => {
|
|
4121
|
+
await showContextMenu2(uid, menuId, x, y, args);
|
|
4122
|
+
};
|
|
4123
|
+
|
|
4124
|
+
const handleContextMenu = async (state, button, eventX, eventY) => {
|
|
4125
|
+
const {
|
|
4126
|
+
uid
|
|
4127
|
+
} = state;
|
|
4128
|
+
await show2(uid, MenuIdTitleBarContextMenu, eventX, eventY, {
|
|
4129
|
+
menuId: MenuIdTitleBarContextMenu
|
|
4130
|
+
});
|
|
4131
|
+
return state;
|
|
4132
|
+
};
|
|
4133
|
+
|
|
4134
|
+
const handleElectronMenuClick = async (state, label) => {
|
|
4135
|
+
const {
|
|
4136
|
+
commandMap
|
|
4137
|
+
} = state;
|
|
4138
|
+
const commandPair = commandMap[label];
|
|
4139
|
+
if (!commandPair) {
|
|
4140
|
+
throw new Error(`no command found for ${label}`);
|
|
4141
|
+
}
|
|
4142
|
+
const {
|
|
4143
|
+
args = [],
|
|
4144
|
+
command
|
|
4145
|
+
} = commandPair;
|
|
4146
|
+
await invoke$1(command, ...args);
|
|
4147
|
+
return state;
|
|
4148
|
+
};
|
|
4149
|
+
|
|
4150
|
+
const state = {
|
|
4151
|
+
connected: false
|
|
4152
|
+
};
|
|
4153
|
+
const isConnected = () => {
|
|
4154
|
+
const {
|
|
4155
|
+
connected
|
|
4156
|
+
} = state;
|
|
4157
|
+
return connected;
|
|
4158
|
+
};
|
|
4159
|
+
const invoke = (method, ...params) => {
|
|
4160
|
+
return invoke$2(method, ...params);
|
|
4161
|
+
};
|
|
4162
|
+
const set = rpc => {
|
|
4163
|
+
set$3(rpc);
|
|
4164
|
+
state.connected = true;
|
|
4165
|
+
};
|
|
4166
|
+
|
|
4167
|
+
const commandQueues = new Map();
|
|
4168
|
+
const handleMessagePort = async (port, viewletCommandMap, setAsRendererProcess = true) => {
|
|
4169
|
+
const executeViewletCommand = async (uid, command, ...args) => {
|
|
4170
|
+
const fn = viewletCommandMap[`TitleBar.${command}`];
|
|
4171
|
+
if (typeof fn !== 'function') {
|
|
4172
|
+
throw new TypeError(`Viewlet command not found: ${command}`);
|
|
4173
|
+
}
|
|
4174
|
+
const previous = commandQueues.get(uid);
|
|
4175
|
+
const {
|
|
4176
|
+
promise: next,
|
|
4177
|
+
resolve
|
|
4178
|
+
} = Promise.withResolvers();
|
|
4179
|
+
commandQueues.set(uid, next);
|
|
4180
|
+
if (previous) {
|
|
4181
|
+
await previous;
|
|
4182
|
+
}
|
|
4183
|
+
try {
|
|
4184
|
+
await fn(uid, ...args);
|
|
4185
|
+
await invoke$1('Viewlet.requestRender', uid);
|
|
4186
|
+
} finally {
|
|
4187
|
+
resolve();
|
|
4188
|
+
if (commandQueues.get(uid) === next) {
|
|
4189
|
+
commandQueues.delete(uid);
|
|
4190
|
+
}
|
|
4191
|
+
}
|
|
4192
|
+
};
|
|
4193
|
+
const rpc = await create$6({
|
|
4194
|
+
commandMap: {
|
|
4195
|
+
'Viewlet.executeViewletCommand': executeViewletCommand
|
|
4196
|
+
},
|
|
4197
|
+
messagePort: port
|
|
4198
|
+
});
|
|
4199
|
+
if (setAsRendererProcess) {
|
|
4200
|
+
set(rpc);
|
|
4201
|
+
}
|
|
4202
|
+
};
|
|
4203
|
+
|
|
4204
|
+
const getMenuOffset = (x, clientX, iconWidth) => {
|
|
4205
|
+
return clientX - x - iconWidth;
|
|
4206
|
+
};
|
|
4207
|
+
|
|
4208
|
+
const getTitleBarIndexFromPosition = (titleBarEntries, x, y) => {
|
|
4209
|
+
let currentX = 0;
|
|
4210
|
+
for (let i = 0; i < titleBarEntries.length; i++) {
|
|
4211
|
+
const entry = titleBarEntries[i];
|
|
4212
|
+
const entryWidth = entry.width;
|
|
4213
|
+
if (x >= currentX && x < currentX + entryWidth) {
|
|
4214
|
+
return i;
|
|
4215
|
+
}
|
|
4216
|
+
currentX += entryWidth;
|
|
4217
|
+
}
|
|
4218
|
+
return -1;
|
|
4219
|
+
};
|
|
4220
|
+
|
|
4148
4221
|
const focusIndex = async (state, index) => {
|
|
4149
4222
|
object(state);
|
|
4150
4223
|
number(index);
|
|
@@ -4466,7 +4539,7 @@ const renderFocusedIndex = (oldState, newState) => {
|
|
|
4466
4539
|
if (newState.focusedIndex === -1) {
|
|
4467
4540
|
return [];
|
|
4468
4541
|
}
|
|
4469
|
-
return [FocusSelector, newState.uid, '.
|
|
4542
|
+
return [FocusSelector, newState.uid, '.TitleBarMenuBar'];
|
|
4470
4543
|
};
|
|
4471
4544
|
|
|
4472
4545
|
const getKeyBindingString = (key, altKey, ctrlKey, shiftKey, metaKey) => {
|
|
@@ -4772,13 +4845,18 @@ const renderDirect = async (uid, commands) => {
|
|
|
4772
4845
|
return [...rendererWorkerCommands, ['Viewlet.commitPending', uid, transactionId]];
|
|
4773
4846
|
};
|
|
4774
4847
|
const render3 = async (uid, diffResult) => {
|
|
4848
|
+
// State may change between the renderer worker's diff and render RPCs.
|
|
4849
|
+
const pendingDiffs = new Set([...diffResult, ...diff3(uid)]);
|
|
4775
4850
|
const {
|
|
4776
4851
|
newState,
|
|
4777
4852
|
oldState
|
|
4778
4853
|
} = get(uid);
|
|
4779
4854
|
set$1(uid, newState, newState);
|
|
4780
4855
|
const commands = [];
|
|
4781
|
-
for (const item of
|
|
4856
|
+
for (const item of numbers) {
|
|
4857
|
+
if (!pendingDiffs.has(item)) {
|
|
4858
|
+
continue;
|
|
4859
|
+
}
|
|
4782
4860
|
const fn = getRenderer3(item);
|
|
4783
4861
|
const result = fn(oldState, newState);
|
|
4784
4862
|
if (result.length > 0) {
|
|
@@ -4826,7 +4904,7 @@ const renderEventListeners = () => {
|
|
|
4826
4904
|
params: ['handleMenuMouseOver', ClientX, ClientY]
|
|
4827
4905
|
}, {
|
|
4828
4906
|
name: HandleClick,
|
|
4829
|
-
params: ['
|
|
4907
|
+
params: ['handleClickByName', Button, TargetName]
|
|
4830
4908
|
}, {
|
|
4831
4909
|
name: HandlePointerOut,
|
|
4832
4910
|
params: ['handlePointerOut', ClientX, ClientY]
|
|
@@ -4971,30 +5049,6 @@ const create = (id, uri, x, y, width, height) => {
|
|
|
4971
5049
|
return state;
|
|
4972
5050
|
};
|
|
4973
5051
|
|
|
4974
|
-
const closeMenu = (state, keepFocus) => {
|
|
4975
|
-
const {
|
|
4976
|
-
focused,
|
|
4977
|
-
focusedIndex,
|
|
4978
|
-
isMenuOpen,
|
|
4979
|
-
menus
|
|
4980
|
-
} = state;
|
|
4981
|
-
// TODO send to renderer process
|
|
4982
|
-
// 1. close menu
|
|
4983
|
-
// 2. focus top level entry
|
|
4984
|
-
const newFocused = keepFocus ? focused : false;
|
|
4985
|
-
const newFocusedIndex = keepFocus ? focusedIndex : -1;
|
|
4986
|
-
if (!isMenuOpen && menus.length === 0 && focused === newFocused && focusedIndex === newFocusedIndex) {
|
|
4987
|
-
return state;
|
|
4988
|
-
}
|
|
4989
|
-
return {
|
|
4990
|
-
...state,
|
|
4991
|
-
focused: newFocused,
|
|
4992
|
-
focusedIndex: newFocusedIndex,
|
|
4993
|
-
isMenuOpen: false,
|
|
4994
|
-
menus: []
|
|
4995
|
-
};
|
|
4996
|
-
};
|
|
4997
|
-
|
|
4998
5052
|
const first = () => {
|
|
4999
5053
|
return 0;
|
|
5000
5054
|
};
|
|
@@ -5041,33 +5095,6 @@ const focusPrevious = state => {
|
|
|
5041
5095
|
return focusIndex(state, indexToFocus);
|
|
5042
5096
|
};
|
|
5043
5097
|
|
|
5044
|
-
const LeftClick = 0;
|
|
5045
|
-
|
|
5046
|
-
const toggleIndex = async (state, index) => {
|
|
5047
|
-
const {
|
|
5048
|
-
focusedIndex,
|
|
5049
|
-
isMenuOpen
|
|
5050
|
-
} = state;
|
|
5051
|
-
if (isMenuOpen && focusedIndex === index) {
|
|
5052
|
-
return closeMenu(state, /* keepFocus */true);
|
|
5053
|
-
}
|
|
5054
|
-
return openMenuAtIndex(state, index, /* focus */false);
|
|
5055
|
-
};
|
|
5056
|
-
|
|
5057
|
-
const handleClick = async (state, button, index) => {
|
|
5058
|
-
if (button !== LeftClick) {
|
|
5059
|
-
return state;
|
|
5060
|
-
}
|
|
5061
|
-
if (index === -1) {
|
|
5062
|
-
return state;
|
|
5063
|
-
}
|
|
5064
|
-
const newState = await toggleIndex(state, index);
|
|
5065
|
-
return {
|
|
5066
|
-
...newState,
|
|
5067
|
-
focused: true
|
|
5068
|
-
};
|
|
5069
|
-
};
|
|
5070
|
-
|
|
5071
5098
|
const handleClickAt = async (state, button, eventX, eventY) => {
|
|
5072
5099
|
const {
|
|
5073
5100
|
iconWidth,
|
|
@@ -5616,6 +5643,7 @@ const commandMap = {
|
|
|
5616
5643
|
'TitleBar.handleButtonsClick': handleClick$1,
|
|
5617
5644
|
'TitleBar.handleClick': wrapCommand(handleClick),
|
|
5618
5645
|
'TitleBar.handleClickAt': wrapCommand(handleClickAt),
|
|
5646
|
+
'TitleBar.handleClickByName': wrapCommand(handleClickByName),
|
|
5619
5647
|
'TitleBar.handleClickClose': wrapCommand(handleClickClose),
|
|
5620
5648
|
'TitleBar.handleClickMinimize': wrapCommand(handleClickMinimize),
|
|
5621
5649
|
'TitleBar.handleClickToggleMaximize': wrapCommand(handleClickToggleMaximize),
|
|
@@ -5642,7 +5670,8 @@ const commandMap = {
|
|
|
5642
5670
|
'TitleBar.handlePointerOut': wrapCommand(handlePointerOut),
|
|
5643
5671
|
'TitleBar.handlePointerOver': wrapCommand(handlePointerOver),
|
|
5644
5672
|
'TitleBar.handleTitleBarContextMenu': wrapCommand(handleTitleBarContextMenu),
|
|
5645
|
-
|
|
5673
|
+
// Workspace actions await this callback while holding the ordinary command queue.
|
|
5674
|
+
'TitleBar.handleWorkspaceChange': wrapNotification(handleWorkspaceChange),
|
|
5646
5675
|
'TitleBar.hideCommandCenter': wrapCommand(hideCommandCenter),
|
|
5647
5676
|
'TitleBar.hideMenuBar': wrapCommand(hideMenuBar),
|
|
5648
5677
|
'TitleBar.hydrateElectronApplicationMenu': wrapCommand(hydrate),
|