@lvce-editor/find-widget-worker 2.7.0 → 3.2.0

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.
@@ -182,8 +182,8 @@ const getModuleNotFoundError = stderr => {
182
182
  const messageIndex = lines.findIndex(isModuleNotFoundMessage);
183
183
  const message = lines[messageIndex];
184
184
  return {
185
- message,
186
- code: ERR_MODULE_NOT_FOUND
185
+ code: ERR_MODULE_NOT_FOUND,
186
+ message
187
187
  };
188
188
  };
189
189
  const isModuleNotFoundError = stderr => {
@@ -206,14 +206,14 @@ const isUnhelpfulNativeModuleError = stderr => {
206
206
  const getNativeModuleErrorMessage = stderr => {
207
207
  const message = getMessageCodeBlock(stderr);
208
208
  return {
209
- message: `Incompatible native node module: ${message}`,
210
- code: E_INCOMPATIBLE_NATIVE_MODULE
209
+ code: E_INCOMPATIBLE_NATIVE_MODULE,
210
+ message: `Incompatible native node module: ${message}`
211
211
  };
212
212
  };
213
213
  const getModuleSyntaxError = () => {
214
214
  return {
215
- message: `ES Modules are not supported in electron`,
216
- code: E_MODULES_NOT_SUPPORTED_IN_ELECTRON
215
+ code: E_MODULES_NOT_SUPPORTED_IN_ELECTRON,
216
+ message: `ES Modules are not supported in electron`
217
217
  };
218
218
  };
219
219
  const getHelpfulChildProcessError = (stdout, stderr) => {
@@ -232,8 +232,8 @@ const getHelpfulChildProcessError = (stdout, stderr) => {
232
232
  rest
233
233
  } = getDetails(lines);
234
234
  return {
235
- message: actualMessage,
236
235
  code: '',
236
+ message: actualMessage,
237
237
  stack: rest
238
238
  };
239
239
  };
@@ -243,8 +243,8 @@ class IpcError extends VError {
243
243
  if (stdout || stderr) {
244
244
  // @ts-ignore
245
245
  const {
246
- message,
247
246
  code,
247
+ message,
248
248
  stack
249
249
  } = getHelpfulChildProcessError(stdout, stderr);
250
250
  const cause = new Error(message);
@@ -305,8 +305,8 @@ const wrap$f = global => {
305
305
  };
306
306
  const waitForFirstMessage = async port => {
307
307
  const {
308
- resolve,
309
- promise
308
+ promise,
309
+ resolve
310
310
  } = Promise.withResolvers();
311
311
  port.addEventListener('message', resolve, {
312
312
  once: true
@@ -326,8 +326,8 @@ const listen$6 = async () => {
326
326
  const type = firstMessage.params[0];
327
327
  if (type === 'message-port') {
328
328
  parentIpc.send({
329
- jsonrpc: '2.0',
330
329
  id: firstMessage.id,
330
+ jsonrpc: '2.0',
331
331
  result: null
332
332
  });
333
333
  parentIpc.dispose();
@@ -369,56 +369,14 @@ const IpcChildWithModuleWorkerAndMessagePort$1 = {
369
369
  wrap: wrap$e
370
370
  };
371
371
 
372
- const Two = '2.0';
373
- const create$4 = (method, params) => {
374
- return {
375
- jsonrpc: Two,
376
- method,
377
- params
378
- };
379
- };
372
+ const Two$1 = '2.0';
380
373
  const callbacks = Object.create(null);
381
- const set$4 = (id, fn) => {
382
- callbacks[id] = fn;
383
- };
384
374
  const get$2 = id => {
385
375
  return callbacks[id];
386
376
  };
387
377
  const remove = id => {
388
378
  delete callbacks[id];
389
379
  };
390
- let id = 0;
391
- const create$3$1 = () => {
392
- return ++id;
393
- };
394
- const registerPromise = () => {
395
- const id = create$3$1();
396
- const {
397
- resolve,
398
- promise
399
- } = Promise.withResolvers();
400
- set$4(id, resolve);
401
- return {
402
- id,
403
- promise
404
- };
405
- };
406
- const create$2$1 = (method, params) => {
407
- const {
408
- id,
409
- promise
410
- } = registerPromise();
411
- const message = {
412
- jsonrpc: Two,
413
- method,
414
- params,
415
- id
416
- };
417
- return {
418
- message,
419
- promise
420
- };
421
- };
422
380
  class JsonRpcError extends Error {
423
381
  constructor(message) {
424
382
  super(message);
@@ -612,9 +570,9 @@ const getErrorProperty = (error, prettyError) => {
612
570
  }
613
571
  };
614
572
  };
615
- const create$1$1 = (id, error) => {
573
+ const create$1$2 = (id, error) => {
616
574
  return {
617
- jsonrpc: Two,
575
+ jsonrpc: Two$1,
618
576
  id,
619
577
  error
620
578
  };
@@ -623,22 +581,22 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
623
581
  const prettyError = preparePrettyError(error);
624
582
  logError(error, prettyError);
625
583
  const errorProperty = getErrorProperty(error, prettyError);
626
- return create$1$1(id, errorProperty);
584
+ return create$1$2(id, errorProperty);
627
585
  };
628
- const create$5 = (message, result) => {
586
+ const create$3 = (message, result) => {
629
587
  return {
630
- jsonrpc: Two,
588
+ jsonrpc: Two$1,
631
589
  id: message.id,
632
590
  result: result ?? null
633
591
  };
634
592
  };
635
593
  const getSuccessResponse = (message, result) => {
636
594
  const resultProperty = result ?? null;
637
- return create$5(message, resultProperty);
595
+ return create$3(message, resultProperty);
638
596
  };
639
597
  const getErrorResponseSimple = (id, error) => {
640
598
  return {
641
- jsonrpc: Two,
599
+ jsonrpc: Two$1,
642
600
  id,
643
601
  error: {
644
602
  code: Custom,
@@ -725,29 +683,6 @@ const handleJsonRpcMessage = async (...args) => {
725
683
  }
726
684
  throw new JsonRpcError('unexpected message');
727
685
  };
728
- const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
729
- const {
730
- message,
731
- promise
732
- } = create$2$1(method, params);
733
- if (useSendAndTransfer && ipc.sendAndTransfer) {
734
- ipc.sendAndTransfer(message);
735
- } else {
736
- ipc.send(message);
737
- }
738
- const responseMessage = await promise;
739
- return unwrapJsonRpcResult(responseMessage);
740
- };
741
- const send = (transport, method, ...params) => {
742
- const message = create$4(method, params);
743
- transport.send(message);
744
- };
745
- const invoke$2 = (ipc, method, ...params) => {
746
- return invokeHelper(ipc, method, params, false);
747
- };
748
- const invokeAndTransfer$1 = (ipc, method, ...params) => {
749
- return invokeHelper(ipc, method, params, true);
750
- };
751
686
 
752
687
  class CommandNotFoundError extends Error {
753
688
  constructor(command) {
@@ -770,24 +705,87 @@ const execute = (command, ...args) => {
770
705
  return fn(...args);
771
706
  };
772
707
 
708
+ const Two = '2.0';
709
+ const create$s = (method, params) => {
710
+ return {
711
+ jsonrpc: Two,
712
+ method,
713
+ params
714
+ };
715
+ };
716
+ const create$r = (id, method, params) => {
717
+ const message = {
718
+ id,
719
+ jsonrpc: Two,
720
+ method,
721
+ params
722
+ };
723
+ return message;
724
+ };
725
+ let id = 0;
726
+ const create$q = () => {
727
+ return ++id;
728
+ };
729
+
730
+ /* eslint-disable n/no-unsupported-features/es-syntax */
731
+
732
+ const registerPromise = map => {
733
+ const id = create$q();
734
+ const {
735
+ promise,
736
+ resolve
737
+ } = Promise.withResolvers();
738
+ map[id] = resolve;
739
+ return {
740
+ id,
741
+ promise
742
+ };
743
+ };
744
+
745
+ // @ts-ignore
746
+ const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer) => {
747
+ const {
748
+ id,
749
+ promise
750
+ } = registerPromise(callbacks);
751
+ const message = create$r(id, method, params);
752
+ if (useSendAndTransfer && ipc.sendAndTransfer) {
753
+ ipc.sendAndTransfer(message);
754
+ } else {
755
+ ipc.send(message);
756
+ }
757
+ const responseMessage = await promise;
758
+ return unwrapJsonRpcResult(responseMessage);
759
+ };
773
760
  const createRpc = ipc => {
761
+ const callbacks = Object.create(null);
762
+ ipc._resolve = (id, response) => {
763
+ const fn = callbacks[id];
764
+ if (!fn) {
765
+ console.warn(`callback ${id} may already be disposed`);
766
+ return;
767
+ }
768
+ fn(response);
769
+ delete callbacks[id];
770
+ };
774
771
  const rpc = {
772
+ async dispose() {
773
+ await ipc?.dispose();
774
+ },
775
+ invoke(method, ...params) {
776
+ return invokeHelper(callbacks, ipc, method, params, false);
777
+ },
778
+ invokeAndTransfer(method, ...params) {
779
+ return invokeHelper(callbacks, ipc, method, params, true);
780
+ },
775
781
  // @ts-ignore
776
782
  ipc,
777
783
  /**
778
784
  * @deprecated
779
785
  */
780
786
  send(method, ...params) {
781
- send(ipc, method, ...params);
782
- },
783
- invoke(method, ...params) {
784
- return invoke$2(ipc, method, ...params);
785
- },
786
- invokeAndTransfer(method, ...params) {
787
- return invokeAndTransfer$1(ipc, method, ...params);
788
- },
789
- async dispose() {
790
- await ipc?.dispose();
787
+ const message = create$s(method, params);
788
+ ipc.send(message);
791
789
  }
792
790
  };
793
791
  return rpc;
@@ -804,7 +802,7 @@ const logError = () => {
804
802
  const handleMessage = event => {
805
803
  const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket;
806
804
  const actualExecute = event?.target?.execute || execute;
807
- return handleJsonRpcMessage(event.target, event.data, actualExecute, resolve, preparePrettyError, logError, actualRequiresSocket);
805
+ return handleJsonRpcMessage(event.target, event.data, actualExecute, event.target._resolve, preparePrettyError, logError, actualRequiresSocket);
808
806
  };
809
807
  const handleIpc = ipc => {
810
808
  if ('addEventListener' in ipc) {
@@ -822,7 +820,7 @@ const listen$1 = async (module, options) => {
822
820
  const ipc = module.wrap(rawIpc);
823
821
  return ipc;
824
822
  };
825
- const create$3 = async ({
823
+ const create$1$1 = async ({
826
824
  commandMap
827
825
  }) => {
828
826
  // TODO create a commandMap per rpc instance
@@ -834,33 +832,104 @@ const create$3 = async ({
834
832
  };
835
833
  const WebWorkerRpcClient = {
836
834
  __proto__: null,
837
- create: create$3
835
+ create: create$1$1
838
836
  };
839
- const createMockRpc = ({
840
- commandMap
841
- }) => {
842
- const invocations = [];
843
- const invoke = (method, ...params) => {
844
- invocations.push([method, ...params]);
845
- const command = commandMap[method];
846
- if (!command) {
847
- throw new Error(`command ${method} not found`);
837
+
838
+ const ClientX = 'event.clientX';
839
+ const ClientY = 'event.clientY';
840
+ const TargetName = 'event.target.name';
841
+ const TargetValue = 'event.target.value';
842
+
843
+ const Tab = 2;
844
+ const Enter = 3;
845
+ const KeyF = 34;
846
+ const F4 = 60;
847
+
848
+ const User$1 = 1;
849
+ const Script$1 = 2;
850
+
851
+ const CtrlCmd = 1 << 11 >>> 0;
852
+ const Shift = 1 << 10 >>> 0;
853
+ const Alt = 1 << 9 >>> 0;
854
+
855
+ const EditorWorker = 99;
856
+
857
+ const FocusSelector = 'Viewlet.focusSelector';
858
+ const SetCss = 'Viewlet.setCss';
859
+ const SetFocusContext = 'Viewlet.setFocusContext';
860
+ const SetValueByName = 'Viewlet.setValueByName';
861
+
862
+ const FocusFindWidget$1 = 16;
863
+ const FocusFindWidgetCloseButton$1 = 48;
864
+ const FocusFindWidgetNextMatchButton = 49;
865
+ const FocusFindWidgetPreviousMatchButton = 50;
866
+ const FocusFindWidgetReplace$1 = 43;
867
+ const FocusFindWidgetReplaceAllButton$1 = 47;
868
+ const FocusFindWidgetReplaceButton = 46;
869
+ const FocusIgnoreFiles = 1012;
870
+ const FocusSearchExcludeInput = 1008;
871
+ const FocusSearchIncludeInput = 1007;
872
+ const FocusSearchInput = 21;
873
+ const FocusSearchMatchCase = 32;
874
+ const FocusSearchOpenEditors = 1011;
875
+ const FocusSearchPreserveCase = 36;
876
+ const FocusSearchRegex = 33;
877
+ const FocusSearchReplaceAll = 35;
878
+ const FocusSearchReplaceInput = 31;
879
+ const FocusSearchWholeWord = 34;
880
+ const FocusToggleDetails = 1010;
881
+ const FocusToggleReplace = 1020;
882
+
883
+ const rpcs = Object.create(null);
884
+ const set$2 = (id, rpc) => {
885
+ rpcs[id] = rpc;
886
+ };
887
+ const get$1 = id => {
888
+ return rpcs[id];
889
+ };
890
+
891
+ const create$2 = rpcId => {
892
+ return {
893
+ async dispose() {
894
+ const rpc = get$1(rpcId);
895
+ await rpc.dispose();
896
+ },
897
+ // @ts-ignore
898
+ invoke(method, ...params) {
899
+ const rpc = get$1(rpcId);
900
+ // @ts-ignore
901
+ return rpc.invoke(method, ...params);
902
+ },
903
+ // @ts-ignore
904
+ invokeAndTransfer(method, ...params) {
905
+ const rpc = get$1(rpcId);
906
+ // @ts-ignore
907
+ return rpc.invokeAndTransfer(method, ...params);
908
+ },
909
+ set(rpc) {
910
+ set$2(rpcId, rpc);
848
911
  }
849
- return command(...params);
850
912
  };
851
- const mockRpc = {
852
- invoke,
853
- invokeAndTransfer: invoke,
854
- invocations
855
- };
856
- return mockRpc;
913
+ };
914
+
915
+ const {
916
+ invoke,
917
+ set: set$1
918
+ } = create$2(EditorWorker);
919
+ const getLines$1 = async editorUid => {
920
+ const lines = await invoke('Editor.getLines2', editorUid);
921
+ return lines;
922
+ };
923
+ const getSelections$1 = async editorUid => {
924
+ const selections = await invoke('Editor.getSelections2', editorUid);
925
+ return selections;
857
926
  };
858
927
 
859
928
  const toCommandId = key => {
860
929
  const dotIndex = key.indexOf('.');
861
930
  return key.slice(dotIndex + 1);
862
931
  };
863
- const create$2 = () => {
932
+ const create$1 = () => {
864
933
  const states = Object.create(null);
865
934
  const commandMapRef = {};
866
935
  return {
@@ -941,262 +1010,69 @@ const terminate = () => {
941
1010
  globalThis.close();
942
1011
  };
943
1012
 
944
- const CheckBox = 'checkbox';
945
- const Group = 'group';
946
- const None = 'none';
947
-
948
- const Button = 1;
949
- const Div = 4;
950
- const Text = 12;
951
- const TextArea = 62;
952
-
953
- const ClientX = 'event.clientX';
954
- const ClientY = 'event.clientY';
955
- const TargetName = 'event.target.name';
956
-
957
- const Tab = 2;
958
- const Enter = 3;
959
- const KeyF = 34;
960
- const F4 = 60;
961
-
962
- const User$1 = 1;
963
- const Script$1 = 2;
964
-
965
- const CtrlCmd = 1 << 11 >>> 0;
966
- const Shift = 1 << 10 >>> 0;
967
- const Alt = 1 << 9 >>> 0;
1013
+ const close$1 = async state => {
1014
+ const {
1015
+ editorUid
1016
+ } = state;
1017
+ // @ts-ignore
1018
+ await invoke('Editor.closeFind2', editorUid);
1019
+ return state;
1020
+ };
968
1021
 
969
- const EditorWorker$1 = 99;
1022
+ const {
1023
+ dispose: dispose$1,
1024
+ get,
1025
+ getCommandIds,
1026
+ registerCommands,
1027
+ set,
1028
+ wrapCommand,
1029
+ wrapGetter
1030
+ } = create$1();
970
1031
 
971
- const FocusSelector = 'Viewlet.focusSelector';
972
- const SetCss = 'Viewlet.setCss';
973
- const SetFocusContext = 'Viewlet.setFocusContext';
974
- const SetValueByName = 'Viewlet.setValueByName';
975
-
976
- const FocusFindWidget$1 = 16;
977
- const FocusFindWidgetCloseButton$1 = 48;
978
- const FocusFindWidgetNextMatchButton = 49;
979
- const FocusFindWidgetPreviousMatchButton = 50;
980
- const FocusFindWidgetReplace$1 = 43;
981
- const FocusFindWidgetReplaceAllButton$1 = 47;
982
- const FocusFindWidgetReplaceButton = 46;
983
- const FocusIgnoreFiles = 1012;
984
- const FocusSearchExcludeInput = 1008;
985
- const FocusSearchIncludeInput = 1007;
986
- const FocusSearchInput = 21;
987
- const FocusSearchMatchCase = 32;
988
- const FocusSearchOpenEditors = 1011;
989
- const FocusSearchPreserveCase = 36;
990
- const FocusSearchRegex = 33;
991
- const FocusSearchReplaceAll = 35;
992
- const FocusSearchReplaceInput = 31;
993
- const FocusSearchWholeWord = 34;
994
- const FocusToggleDetails = 1010;
995
- const FocusToggleReplace = 1020;
996
-
997
- const rpcs = Object.create(null);
998
- const set$3 = (id, rpc) => {
999
- rpcs[id] = rpc;
1000
- };
1001
- const get$1 = id => {
1002
- return rpcs[id];
1003
- };
1004
-
1005
- const create$1 = rpcId => {
1006
- return {
1007
- // @ts-ignore
1008
- invoke(method, ...params) {
1009
- const rpc = get$1(rpcId);
1010
- // @ts-ignore
1011
- return rpc.invoke(method, ...params);
1012
- },
1013
- // @ts-ignore
1014
- invokeAndTransfer(method, ...params) {
1015
- const rpc = get$1(rpcId);
1016
- // @ts-ignore
1017
- return rpc.invokeAndTransfer(method, ...params);
1018
- },
1019
- set(rpc) {
1020
- set$3(rpcId, rpc);
1021
- },
1022
- async dispose() {
1023
- const rpc = get$1(rpcId);
1024
- await rpc.dispose();
1025
- }
1026
- };
1027
- };
1028
-
1029
- const {
1030
- invoke: invoke$1,
1031
- invokeAndTransfer,
1032
- set: set$2,
1033
- dispose: dispose$2
1034
- } = create$1(EditorWorker$1);
1035
- const sendMessagePortToExtensionHostWorker = async port => {
1036
- const command = 'HandleMessagePort.handleMessagePort2';
1037
- await invokeAndTransfer(
1038
- // @ts-ignore
1039
- 'SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker', port, command, 0);
1040
- };
1041
- // TODO add tests for this
1042
- const activateByEvent = async event => {
1043
- // @ts-ignore
1044
- await invoke$1('ActivateByEvent.activateByEvent', event);
1045
- };
1046
- const applyEdit = async (editorUid, changes) => {
1047
- // @ts-ignore
1048
- await invoke$1('Editor.applyEdit2', editorUid, changes);
1049
- };
1050
- const applyWorkspaceEdit = async (editorUid, changes) => {
1051
- // @ts-ignore
1052
- await invoke$1('Editor.applyWorkspaceEdit', editorUid, changes);
1053
- };
1054
- const closeWidget = async (editorUid, widgetId, widgetName, focusId) => {
1055
- // @ts-ignore
1056
- await invoke$1('Editor.closeWidget2', editorUid, widgetId, widgetName, focusId);
1057
- };
1058
- const getWordAt = async (uid, rowIndex, columnIndex) => {
1059
- // @ts-ignore
1060
- const word = await invoke$1('Editor.getWordAt2', uid, rowIndex, columnIndex);
1061
- return word;
1062
- };
1063
- const getLines$1 = async editorUid => {
1064
- const lines = await invoke$1('Editor.getLines2', editorUid);
1065
- return lines;
1066
- };
1067
- const getPositionAtCursor = async parentUid => {
1068
- const position = await invoke$1('Editor.getPositionAtCursor', parentUid);
1069
- return position;
1070
- };
1071
- const getOffsetAtCursor = async editorId => {
1072
- // @ts-ignore
1073
- return await invoke$1('Editor.getOffsetAtCursor', editorId);
1074
- };
1075
- const getSelections$1 = async editorUid => {
1076
- const selections = await invoke$1('Editor.getSelections2', editorUid);
1077
- return selections;
1078
- };
1079
- const getWordAtOffset2 = async editorUid => {
1080
- return invoke$1('Editor.getWordAtOffset2', editorUid);
1081
- };
1082
- const getWordBefore = async (editorUid, rowIndex, columnIndex) => {
1083
- return invoke$1('Editor.getWordBefore2', editorUid, rowIndex, columnIndex);
1084
- };
1085
- const updateDebugInfo = async info => {
1086
- await invoke$1('Editor.updateDebugInfo', info);
1087
- };
1088
- const getUri = async editorUid => {
1089
- // @ts-ignore
1090
- return invoke$1('Editor.getUri', editorUid);
1091
- };
1092
- const getLanguageId = async editorUid => {
1093
- // @ts-ignore
1094
- return invoke$1('Editor.getLanguageId', editorUid);
1095
- };
1096
- const getProblems = async () => {
1097
- // @ts-ignore
1098
- return invoke$1('Editor.getProblems');
1099
- };
1100
- const registerMockRpc = commandMap => {
1101
- const mockRpc = createMockRpc({
1102
- commandMap
1103
- });
1104
- set$2(mockRpc);
1105
- return mockRpc;
1106
- };
1107
-
1108
- const EditorWorker = {
1109
- __proto__: null,
1110
- activateByEvent,
1111
- applyEdit,
1112
- applyWorkspaceEdit,
1113
- closeWidget,
1114
- dispose: dispose$2,
1115
- getLanguageId,
1116
- getLines: getLines$1,
1117
- getOffsetAtCursor,
1118
- getPositionAtCursor,
1119
- getProblems,
1120
- getSelections: getSelections$1,
1121
- getUri,
1122
- getWordAt,
1123
- getWordAtOffset2,
1124
- getWordBefore,
1125
- invoke: invoke$1,
1126
- invokeAndTransfer,
1127
- registerMockRpc,
1128
- sendMessagePortToExtensionHostWorker,
1129
- set: set$2,
1130
- updateDebugInfo
1131
- };
1132
-
1133
- const {
1134
- invoke,
1135
- set: set$1} = EditorWorker;
1136
-
1137
- const close$1 = async state => {
1138
- const {
1139
- editorUid
1140
- } = state;
1141
- // @ts-ignore
1142
- await invoke('Editor.closeFind2', editorUid);
1143
- return state;
1144
- };
1145
-
1146
- const {
1147
- get,
1148
- set,
1149
- wrapCommand,
1150
- dispose: dispose$1,
1151
- getCommandIds,
1152
- registerCommands,
1153
- wrapGetter
1154
- } = create$2();
1155
-
1156
- const User = 1;
1157
- const Script = 2;
1158
- const Unknown = 0;
1032
+ const User = 1;
1033
+ const Script = 2;
1034
+ const Unknown = 0;
1159
1035
 
1160
1036
  const create = (uid, x, y, width, height, parentUid) => {
1161
1037
  const state = {
1162
- uid,
1163
- value: '',
1164
1038
  ariaAnnouncement: '',
1165
- matches: new Uint32Array(),
1166
- matchIndex: -1,
1167
- matchCount: 0,
1168
- replaceExpanded: false,
1169
- useRegularExpression: false,
1170
- matchCase: false,
1171
- matchWholeWord: false,
1172
- replacement: '',
1039
+ editorHeight: height,
1173
1040
  editorUid: parentUid,
1174
- x: 0,
1175
- y: 0,
1176
- width: 0,
1177
- height: 0,
1178
- focused: false,
1179
- focusSource: Unknown,
1180
- focus: 0,
1181
- version: 0,
1182
- lines: [],
1183
- selections: [],
1041
+ editorWidth: width,
1184
1042
  editorX: x,
1185
1043
  editorY: y,
1186
- editorWidth: width,
1187
- editorHeight: height,
1188
- inputSource: 0,
1189
- preserveCase: false,
1190
- resizerPointerDown: false,
1191
- minWidth: 400,
1044
+ focus: 0,
1045
+ focused: false,
1046
+ focusSource: Unknown,
1047
+ height: 0,
1192
1048
  history: [],
1049
+ inputBorderWidth: 1,
1193
1050
  inputErrorMessage: '',
1194
- searchInputHeight: 15,
1051
+ inputGap: 3,
1195
1052
  inputLineHeight: 15,
1196
- inputPaddingTop: 4,
1197
1053
  inputPaddingBottom: 4,
1198
- inputBorderWidth: 1,
1199
- inputGap: 3
1054
+ inputPaddingTop: 4,
1055
+ inputSource: 0,
1056
+ lines: [],
1057
+ matchCase: false,
1058
+ matchCount: 0,
1059
+ matches: new Uint32Array(),
1060
+ matchIndex: -1,
1061
+ matchWholeWord: false,
1062
+ minWidth: 400,
1063
+ preserveCase: false,
1064
+ replaceExpanded: false,
1065
+ replacement: '',
1066
+ resizerPointerDown: false,
1067
+ searchInputHeight: 15,
1068
+ selections: [],
1069
+ uid,
1070
+ useRegularExpression: false,
1071
+ value: '',
1072
+ version: 0,
1073
+ width: 0,
1074
+ x: 0,
1075
+ y: 0
1200
1076
  };
1201
1077
  set(uid, state, state);
1202
1078
  return state;
@@ -1264,8 +1140,8 @@ const diff = (oldState, newState) => {
1264
1140
 
1265
1141
  const diff2 = uid => {
1266
1142
  const {
1267
- oldState,
1268
- newState
1143
+ newState,
1144
+ oldState
1269
1145
  } = get(uid);
1270
1146
  const diffResult = diff(oldState, newState);
1271
1147
  return diffResult;
@@ -1275,9 +1151,11 @@ const dispose = uid => {
1275
1151
  return dispose$1(uid);
1276
1152
  };
1277
1153
 
1154
+ const FindWidget$1 = 16;
1278
1155
  const FocusFindWidgetCloseButton = 48;
1279
1156
  const FocusFindWidgetReplace = 43;
1280
1157
  const FocusFindWidgetReplaceAllButton = 47;
1158
+ const FocusFindWidgetToggleReplace = 42;
1281
1159
 
1282
1160
  const setFindWidgetFocus = (state, focusKey) => {
1283
1161
  if (state.focus === focusKey) {
@@ -1301,18 +1179,18 @@ const setSelections = async (editorUid, selections) => {
1301
1179
 
1302
1180
  const focusIndex = async (state, index) => {
1303
1181
  const {
1304
- matchIndex,
1305
- matches,
1306
1182
  editorUid,
1307
- value
1183
+ matches,
1184
+ matchIndex
1308
1185
  } = state;
1309
1186
  if (index === matchIndex) {
1310
1187
  return state;
1311
1188
  }
1312
1189
  // // TODO find next match and highlight it
1313
- const matchRowIndex = matches[index * 2];
1314
- const matchColumnIndex = matches[index * 2 + 1];
1315
- const newSelections = new Uint32Array([matchRowIndex, matchColumnIndex, matchRowIndex, matchColumnIndex + value.length]);
1190
+ const matchRowIndex = matches[index * 3];
1191
+ const matchColumnIndex = matches[index * 3 + 1];
1192
+ const matchLength = matches[index * 3 + 2];
1193
+ const newSelections = new Uint32Array([matchRowIndex, matchColumnIndex, matchRowIndex, matchColumnIndex + matchLength]);
1316
1194
  await setSelections(editorUid, newSelections);
1317
1195
  return {
1318
1196
  ...state,
@@ -1331,8 +1209,8 @@ const focusLast = state => {
1331
1209
  };
1332
1210
  const focusNext = state => {
1333
1211
  const {
1334
- matchIndex,
1335
- matchCount
1212
+ matchCount,
1213
+ matchIndex
1336
1214
  } = state;
1337
1215
  if (matchIndex === matchCount - 1) {
1338
1216
  return focusFirst(state);
@@ -1373,8 +1251,8 @@ const escapeRegExpCharacters = value => {
1373
1251
  const buildRegex = (searchString, options) => {
1374
1252
  const {
1375
1253
  matchCase,
1376
- useRegularExpression,
1377
- matchWholeWord
1254
+ matchWholeWord,
1255
+ useRegularExpression
1378
1256
  } = options;
1379
1257
  const flags = matchCase ? 'g' : 'gi';
1380
1258
  const pattern = useRegularExpression ? searchString : escapeRegExpCharacters(searchString);
@@ -1382,13 +1260,13 @@ const buildRegex = (searchString, options) => {
1382
1260
  try {
1383
1261
  const regex = new RegExp(wrapped, flags);
1384
1262
  return {
1385
- regex,
1386
- error: ''
1263
+ error: '',
1264
+ regex
1387
1265
  };
1388
1266
  } catch (error) {
1389
1267
  return {
1390
- regex: new RegExp(''),
1391
- error: `${error}`
1268
+ error: `${error}`,
1269
+ regex: new RegExp('')
1392
1270
  };
1393
1271
  }
1394
1272
  };
@@ -1409,7 +1287,7 @@ const findRegexMatches = (lines, regex) => {
1409
1287
  if (!lastMatch) {
1410
1288
  break;
1411
1289
  }
1412
- matches.push(i, lastMatch.index);
1290
+ matches.push(i, lastMatch.index, lastMatch[0].length);
1413
1291
  } while (true);
1414
1292
  }
1415
1293
  return new Uint32Array(matches);
@@ -1418,29 +1296,29 @@ const findRegexMatches = (lines, regex) => {
1418
1296
  const findMatches = (lines, searchString, options) => {
1419
1297
  if (searchString.length === 0) {
1420
1298
  return {
1421
- matches: new Uint32Array([]),
1422
- error: ''
1299
+ error: '',
1300
+ matches: new Uint32Array([])
1423
1301
  };
1424
1302
  }
1425
1303
  const {
1426
- regex,
1427
- error
1304
+ error,
1305
+ regex
1428
1306
  } = buildRegex(searchString, options);
1429
1307
  if (error) {
1430
1308
  return {
1431
- matches: new Uint32Array([]),
1432
- error
1309
+ error,
1310
+ matches: new Uint32Array([])
1433
1311
  };
1434
1312
  }
1435
1313
  const matches = findRegexMatches(lines, regex);
1436
1314
  return {
1437
- matches,
1438
- error: ''
1315
+ error: '',
1316
+ matches
1439
1317
  };
1440
1318
  };
1441
1319
 
1442
1320
  const getMatchCount = matches => {
1443
- return matches.length / 2;
1321
+ return matches.length / 3;
1444
1322
  };
1445
1323
 
1446
1324
  const measureTextHeight = (value, lineHeight) => {
@@ -1461,57 +1339,57 @@ const measureInputHeight = (value, inputLineHeight, inputPaddingBottom, inputPad
1461
1339
  // TODO use variables for margin
1462
1340
  const height = inputHeight + replaceInputHeight + 5 + actualGap;
1463
1341
  return {
1464
- inputHeight,
1465
1342
  height,
1343
+ inputHeight,
1466
1344
  replaceInputHeight
1467
1345
  };
1468
1346
  };
1469
1347
 
1470
1348
  const refresh$1 = (state, value, inputSource) => {
1471
1349
  const {
1350
+ inputBorderWidth,
1351
+ inputGap,
1352
+ inputLineHeight,
1353
+ inputPaddingBottom,
1354
+ inputPaddingTop,
1472
1355
  lines,
1473
1356
  matchCase,
1474
- useRegularExpression,
1475
1357
  matchWholeWord,
1476
- inputLineHeight,
1477
- inputPaddingTop,
1478
- inputPaddingBottom,
1479
1358
  replaceExpanded,
1480
- inputBorderWidth,
1481
- inputGap
1359
+ useRegularExpression
1482
1360
  } = state;
1483
1361
  const options = {
1484
1362
  matchCase,
1485
- useRegularExpression,
1486
- matchWholeWord
1363
+ matchWholeWord,
1364
+ useRegularExpression
1487
1365
  };
1488
1366
  const {
1489
- matches,
1490
- error
1367
+ error,
1368
+ matches
1491
1369
  } = findMatches(lines, value, options);
1492
1370
  const {
1493
- inputHeight,
1494
- height
1371
+ height,
1372
+ inputHeight
1495
1373
  } = measureInputHeight(value, inputLineHeight, inputPaddingBottom, inputPaddingTop, inputBorderWidth, inputGap, replaceExpanded);
1496
1374
  if (error) {
1497
1375
  return {
1498
1376
  ...state,
1377
+ height,
1499
1378
  inputErrorMessage: error,
1500
- searchInputHeight: inputHeight,
1501
- height
1379
+ searchInputHeight: inputHeight
1502
1380
  };
1503
1381
  }
1504
1382
  const matchCount = getMatchCount(matches);
1505
1383
  return {
1506
1384
  ...state,
1385
+ height,
1507
1386
  inputErrorMessage: error,
1508
- searchInputHeight: inputHeight,
1509
1387
  inputSource,
1510
1388
  matchCount,
1511
1389
  matches,
1512
1390
  matchIndex: 0,
1513
- value,
1514
- height
1391
+ searchInputHeight: inputHeight,
1392
+ value
1515
1393
  };
1516
1394
  };
1517
1395
 
@@ -1581,6 +1459,47 @@ const applyEdits = async (editorId, edits) => {
1581
1459
  await invoke('Editor.applyDocumentEdits', editorId, edits);
1582
1460
  };
1583
1461
 
1462
+ /**
1463
+ * Apply regex replacement with back-reference substitution ($1, $2, etc.)
1464
+ */
1465
+ const applyRegexReplacement = (originalText, regex, replacement) => {
1466
+ // Create a non-global version of the regex to get capture groups
1467
+ const flags = regex.flags.replace('g', '');
1468
+ const nonGlobalRegex = new RegExp(regex.source, flags);
1469
+ const match = nonGlobalRegex.exec(originalText);
1470
+ if (!match) {
1471
+ return replacement;
1472
+ }
1473
+
1474
+ // Replace $n back-references with captured groups
1475
+ let result = replacement;
1476
+
1477
+ // Handle $& (entire match)
1478
+ result = result.replaceAll('$&', match[0]);
1479
+
1480
+ // Handle $` (text before match) - in this context it's empty since we're matching the whole text
1481
+ result = result.replaceAll('$`', '');
1482
+
1483
+ // Handle $' (text after match) - in this context it's empty since we're matching the whole text
1484
+ result = result.replaceAll("$'", '');
1485
+
1486
+ // Handle $$ (literal $)
1487
+ result = result.replaceAll('$$', '\u0000DOLLAR\u0000');
1488
+
1489
+ // Handle $n and $nn (numbered capture groups)
1490
+ result = result.replaceAll(/\$(\d{1,2})/g, (_match, groupNumber) => {
1491
+ const index = Number.parseInt(groupNumber, 10);
1492
+ if (index < match.length) {
1493
+ return match[index] ?? '';
1494
+ }
1495
+ return `$${groupNumber}`;
1496
+ });
1497
+
1498
+ // Restore literal $
1499
+ result = result.replaceAll('\u0000DOLLAR\u0000', '$');
1500
+ return result;
1501
+ };
1502
+
1584
1503
  /**
1585
1504
  * Preserves the case pattern of the original text when replacing.
1586
1505
  * Supports uppercase, lowercase, PascalCase, and camelCase patterns.
@@ -1620,24 +1539,47 @@ const preserveCase$1 = (originalText, replacementText) => {
1620
1539
  return replacementText;
1621
1540
  };
1622
1541
 
1623
- const getEdits = (matches, value, replacement, startIndex, replaceAll, lines, preserveCaseOption = false) => {
1542
+ const getEdits = (matches, value, replacement, startIndex, replaceAll, lines, preserveCaseOption = false, options) => {
1624
1543
  if (value.length === 0 || matches.length === 0) {
1625
1544
  return [];
1626
1545
  }
1627
1546
  const edits = [];
1628
- const totalMatches = Math.floor(matches.length / 2);
1547
+ const totalMatches = Math.floor(matches.length / 3);
1629
1548
  const fromIndex = replaceAll ? 0 : Math.max(0, startIndex);
1630
1549
  const toIndex = replaceAll ? totalMatches : Math.min(totalMatches, fromIndex + 1);
1550
+
1551
+ // Build regex once if using regular expressions
1552
+ let regex;
1553
+ if (options?.useRegularExpression) {
1554
+ const {
1555
+ error,
1556
+ regex: builtRegex
1557
+ } = buildRegex(value, options);
1558
+ if (!error) {
1559
+ regex = builtRegex;
1560
+ }
1561
+ }
1631
1562
  for (let i = fromIndex; i < toIndex; i++) {
1632
- const rowIndex = matches[i * 2];
1633
- const startColumnIndex = matches[i * 2 + 1];
1634
- const endColumnIndex = startColumnIndex + value.length;
1563
+ const rowIndex = matches[i * 3];
1564
+ const startColumnIndex = matches[i * 3 + 1];
1565
+ const matchLength = matches[i * 3 + 2];
1566
+ const endColumnIndex = startColumnIndex + matchLength;
1635
1567
 
1636
1568
  // Get the original text that was matched
1637
1569
  const originalText = lines[rowIndex].slice(startColumnIndex, endColumnIndex);
1638
1570
 
1571
+ // Apply regex replacement with back-references if enabled
1572
+ let finalReplacement;
1573
+ if (options?.useRegularExpression && regex) {
1574
+ finalReplacement = applyRegexReplacement(originalText, regex, replacement);
1575
+ } else {
1576
+ finalReplacement = replacement;
1577
+ }
1578
+
1639
1579
  // Apply case preservation if enabled
1640
- const finalReplacement = preserveCaseOption ? preserveCase$1(originalText, replacement) : replacement;
1580
+ if (preserveCaseOption) {
1581
+ finalReplacement = preserveCase$1(originalText, finalReplacement);
1582
+ }
1641
1583
 
1642
1584
  // Convert row/column positions to character offsets
1643
1585
  let startOffset = 0;
@@ -1651,10 +1593,10 @@ const getEdits = (matches, value, replacement, startIndex, replaceAll, lines, pr
1651
1593
  }
1652
1594
  endOffset += endColumnIndex;
1653
1595
  edits.push({
1654
- startOffset,
1655
1596
  endOffset,
1656
1597
  inserted: finalReplacement,
1657
- origin: 'find-widget.replace'
1598
+ origin: 'find-widget.replace',
1599
+ startOffset
1658
1600
  });
1659
1601
  }
1660
1602
  return edits;
@@ -1662,18 +1604,24 @@ const getEdits = (matches, value, replacement, startIndex, replaceAll, lines, pr
1662
1604
 
1663
1605
  const replace$1 = async state => {
1664
1606
  const {
1665
- matches,
1666
- value,
1667
- replacement,
1668
- matchIndex,
1669
1607
  editorUid,
1670
1608
  lines,
1671
- preserveCase
1609
+ matchCase,
1610
+ matches,
1611
+ matchIndex,
1612
+ matchWholeWord,
1613
+ preserveCase,
1614
+ replacement,
1615
+ useRegularExpression,
1616
+ value
1672
1617
  } = state;
1673
- const edits = getEdits(matches, value, replacement, matchIndex, false, lines, preserveCase);
1618
+ const options = {
1619
+ matchCase,
1620
+ matchWholeWord,
1621
+ useRegularExpression
1622
+ };
1623
+ const edits = getEdits(matches, value, replacement, matchIndex, false, lines, preserveCase, options);
1674
1624
  await applyEdits(editorUid, edits);
1675
- // TODO ask editor worker to apply edit
1676
- // TODO ask editor worker for new lines?
1677
1625
  return {
1678
1626
  ...state
1679
1627
  };
@@ -1681,14 +1629,22 @@ const replace$1 = async state => {
1681
1629
 
1682
1630
  const replaceAll$1 = state => {
1683
1631
  const {
1684
- matches,
1685
- value,
1686
- replacement,
1687
1632
  editorUid,
1688
1633
  lines,
1689
- preserveCase
1634
+ matchCase,
1635
+ matches,
1636
+ matchWholeWord,
1637
+ preserveCase,
1638
+ replacement,
1639
+ useRegularExpression,
1640
+ value
1690
1641
  } = state;
1691
- const edits = getEdits(matches, value, replacement, 0, true, lines, preserveCase);
1642
+ const options = {
1643
+ matchCase,
1644
+ matchWholeWord,
1645
+ useRegularExpression
1646
+ };
1647
+ const edits = getEdits(matches, value, replacement, 0, true, lines, preserveCase, options);
1692
1648
  void applyEdits(editorUid, edits);
1693
1649
  return {
1694
1650
  ...state
@@ -1697,18 +1653,18 @@ const replaceAll$1 = state => {
1697
1653
 
1698
1654
  const getClickHandler = name => {
1699
1655
  switch (name) {
1700
- case Replace$2:
1701
- return replace$1;
1702
- case ReplaceAll$2:
1703
- return replaceAll$1;
1704
1656
  case MatchCase$2:
1705
1657
  return toggleMatchCase;
1706
1658
  case MatchWholeWord$2:
1707
1659
  return toggleMatchWholeWord;
1708
- case UseRegularExpression$2:
1709
- return toggleUseRegularExpression;
1710
1660
  case PreserveCase$1:
1711
1661
  return togglePreserveCase;
1662
+ case Replace$2:
1663
+ return replace$1;
1664
+ case ReplaceAll$2:
1665
+ return replaceAll$1;
1666
+ case UseRegularExpression$2:
1667
+ return toggleUseRegularExpression;
1712
1668
  default:
1713
1669
  throw new Error(`unexpected click`);
1714
1670
  }
@@ -1724,7 +1680,10 @@ const handleClickClose = state => {
1724
1680
  };
1725
1681
 
1726
1682
  const handleFindWidgetFocus = (state, focusKey) => {
1727
- if (state.focus === focusKey) {
1683
+ const {
1684
+ focus
1685
+ } = state;
1686
+ if (!focusKey || focus === focusKey) {
1728
1687
  return state;
1729
1688
  }
1730
1689
  return {
@@ -1734,6 +1693,11 @@ const handleFindWidgetFocus = (state, focusKey) => {
1734
1693
  };
1735
1694
  };
1736
1695
 
1696
+ const handleFindFocus = state => {
1697
+ return handleFindWidgetFocus(state, FindWidget$1);
1698
+ };
1699
+
1700
+ // TODO maybe use one handleFocus function with a name parameter
1737
1701
  const handleReplaceFocus = state => {
1738
1702
  return handleFindWidgetFocus(state, FocusFindWidgetReplace);
1739
1703
  };
@@ -1755,10 +1719,10 @@ const getNewCoordinates = (oldWidth, oldX, eventX, minWidth) => {
1755
1719
  };
1756
1720
  const handleResizerPointerMove = async (state, eventX, eventY) => {
1757
1721
  const {
1758
- width,
1759
- x,
1722
+ minWidth,
1760
1723
  resizerPointerDown,
1761
- minWidth
1724
+ width,
1725
+ x
1762
1726
  } = state;
1763
1727
  if (!resizerPointerDown) {
1764
1728
  return state;
@@ -1769,8 +1733,8 @@ const handleResizerPointerMove = async (state, eventX, eventY) => {
1769
1733
  } = getNewCoordinates(width, x, eventX, minWidth);
1770
1734
  return {
1771
1735
  ...state,
1772
- x: newX,
1773
- width: newWidth
1736
+ width: newWidth,
1737
+ x: newX
1774
1738
  };
1775
1739
  };
1776
1740
 
@@ -1781,15 +1745,19 @@ const handleResizerPointerUp = async (state, eventX, eventY) => {
1781
1745
  };
1782
1746
  };
1783
1747
 
1748
+ const handleToggleReplaceFocus = state => {
1749
+ return handleFindWidgetFocus(state, FocusFindWidgetToggleReplace);
1750
+ };
1751
+
1784
1752
  const toggleReplace$1 = state => {
1785
1753
  const {
1786
- replaceExpanded,
1787
- value,
1754
+ inputBorderWidth,
1755
+ inputGap,
1788
1756
  inputLineHeight,
1789
1757
  inputPaddingBottom,
1790
1758
  inputPaddingTop,
1791
- inputBorderWidth,
1792
- inputGap
1759
+ replaceExpanded,
1760
+ value
1793
1761
  } = state;
1794
1762
  const newExpanded = !replaceExpanded;
1795
1763
  const {
@@ -1797,8 +1765,8 @@ const toggleReplace$1 = state => {
1797
1765
  } = measureInputHeight(value, inputLineHeight, inputPaddingBottom, inputPaddingTop, inputBorderWidth, inputGap, newExpanded);
1798
1766
  return {
1799
1767
  ...state,
1800
- replaceExpanded: newExpanded,
1801
- height
1768
+ height,
1769
+ replaceExpanded: newExpanded
1802
1770
  };
1803
1771
  };
1804
1772
 
@@ -1812,8 +1780,10 @@ const focusElement = (state, whenExpression) => {
1812
1780
 
1813
1781
  const getNextFocus = (focus, replaceExpanded) => {
1814
1782
  switch (focus) {
1815
- case FocusToggleReplace:
1816
- return FocusSearchInput;
1783
+ case FocusSearchExcludeInput:
1784
+ return FocusIgnoreFiles;
1785
+ case FocusSearchIncludeInput:
1786
+ return FocusSearchOpenEditors;
1817
1787
  case FocusSearchInput:
1818
1788
  if (replaceExpanded) {
1819
1789
  return FocusSearchReplaceInput;
@@ -1821,27 +1791,25 @@ const getNextFocus = (focus, replaceExpanded) => {
1821
1791
  return FocusSearchMatchCase;
1822
1792
  case FocusSearchMatchCase:
1823
1793
  return FocusSearchWholeWord;
1824
- case FocusSearchWholeWord:
1825
- return FocusSearchRegex;
1794
+ case FocusSearchOpenEditors:
1795
+ return FocusSearchExcludeInput;
1796
+ case FocusSearchPreserveCase:
1797
+ return FocusSearchReplaceAll;
1826
1798
  case FocusSearchRegex:
1827
1799
  if (replaceExpanded) {
1828
1800
  return FocusSearchPreserveCase;
1829
1801
  }
1830
1802
  return FocusFindWidgetCloseButton$1;
1831
- case FocusSearchReplaceInput:
1832
- return FocusSearchMatchCase;
1833
- case FocusSearchPreserveCase:
1834
- return FocusSearchReplaceAll;
1835
1803
  case FocusSearchReplaceAll:
1836
1804
  return FocusToggleDetails;
1837
- case FocusSearchIncludeInput:
1838
- return FocusSearchOpenEditors;
1839
- case FocusSearchOpenEditors:
1840
- return FocusSearchExcludeInput;
1841
- case FocusSearchExcludeInput:
1842
- return FocusIgnoreFiles;
1805
+ case FocusSearchReplaceInput:
1806
+ return FocusSearchMatchCase;
1807
+ case FocusSearchWholeWord:
1808
+ return FocusSearchRegex;
1843
1809
  case FocusToggleDetails:
1844
1810
  return FocusSearchIncludeInput;
1811
+ case FocusToggleReplace:
1812
+ return FocusSearchInput;
1845
1813
  default:
1846
1814
  return focus;
1847
1815
  }
@@ -1858,6 +1826,14 @@ const focusNextElement = state => {
1858
1826
 
1859
1827
  const getPreviousFocus = (focus, replaceExpanded) => {
1860
1828
  switch (focus) {
1829
+ case FocusFindWidgetCloseButton$1:
1830
+ return FocusSearchRegex;
1831
+ case FocusIgnoreFiles:
1832
+ return FocusSearchExcludeInput;
1833
+ case FocusSearchExcludeInput:
1834
+ return FocusSearchOpenEditors;
1835
+ case FocusSearchIncludeInput:
1836
+ return FocusToggleDetails;
1861
1837
  case FocusSearchInput:
1862
1838
  return FocusToggleReplace;
1863
1839
  case FocusSearchMatchCase:
@@ -1865,31 +1841,23 @@ const getPreviousFocus = (focus, replaceExpanded) => {
1865
1841
  return FocusSearchReplaceInput;
1866
1842
  }
1867
1843
  return FocusSearchInput;
1868
- case FocusSearchWholeWord:
1869
- return FocusSearchMatchCase;
1870
- case FocusSearchRegex:
1871
- return FocusSearchWholeWord;
1844
+ case FocusSearchOpenEditors:
1845
+ return FocusSearchIncludeInput;
1872
1846
  case FocusSearchPreserveCase:
1873
1847
  return FocusSearchRegex;
1874
- case FocusSearchReplaceInput:
1875
- return FocusSearchInput;
1848
+ case FocusSearchRegex:
1849
+ return FocusSearchWholeWord;
1876
1850
  case FocusSearchReplaceAll:
1877
1851
  return FocusSearchPreserveCase;
1852
+ case FocusSearchReplaceInput:
1853
+ return FocusSearchInput;
1854
+ case FocusSearchWholeWord:
1855
+ return FocusSearchMatchCase;
1878
1856
  case FocusToggleDetails:
1879
1857
  if (replaceExpanded) {
1880
1858
  return FocusSearchReplaceAll;
1881
1859
  }
1882
1860
  return FocusSearchRegex;
1883
- case FocusSearchOpenEditors:
1884
- return FocusSearchIncludeInput;
1885
- case FocusSearchExcludeInput:
1886
- return FocusSearchOpenEditors;
1887
- case FocusIgnoreFiles:
1888
- return FocusSearchExcludeInput;
1889
- case FocusSearchIncludeInput:
1890
- return FocusToggleDetails;
1891
- case FocusFindWidgetCloseButton$1:
1892
- return FocusSearchRegex;
1893
1861
  default:
1894
1862
  return focus;
1895
1863
  }
@@ -1906,76 +1874,80 @@ const focusPreviousElement = state => {
1906
1874
 
1907
1875
  const getKeyBindings = () => {
1908
1876
  return [{
1909
- key: Enter,
1910
1877
  command: 'FindWidget.focusNext',
1878
+ key: Enter,
1911
1879
  when: FocusFindWidget$1
1912
1880
  }, {
1913
- key: CtrlCmd | KeyF,
1914
1881
  command: 'FindWidget.preventDefaultBrowserFind',
1882
+ key: CtrlCmd | KeyF,
1915
1883
  when: FocusFindWidget$1
1916
1884
  }, {
1917
- key: Shift | F4,
1918
1885
  command: 'FindWidget.focusPrevious',
1886
+ key: Shift | F4,
1919
1887
  when: FocusFindWidget$1
1920
1888
  }, {
1921
- key: F4,
1922
1889
  command: 'FindWidget.focusNext',
1890
+ key: F4,
1923
1891
  when: FocusFindWidget$1
1924
1892
  }, {
1925
- key: Shift | Tab,
1926
1893
  command: 'FindWidget.focusToggleReplace',
1894
+ key: Shift | Tab,
1927
1895
  when: FocusFindWidget$1
1928
1896
  }, {
1929
- key: Tab,
1930
1897
  command: 'FindWidget.focusReplace',
1898
+ key: Tab,
1931
1899
  when: FocusFindWidget$1
1932
1900
  }, {
1933
- key: Tab,
1934
1901
  command: 'FindWidget.focusPreviousMatchButton',
1902
+ key: Tab,
1903
+ when: FocusFindWidgetReplace$1
1904
+ }, {
1905
+ command: 'FindWidget.replace',
1906
+ key: Enter,
1935
1907
  when: FocusFindWidgetReplace$1
1936
1908
  }, {
1937
- key: Alt | CtrlCmd | Enter,
1938
1909
  command: 'FindWidget.replaceAll',
1910
+ key: Alt | CtrlCmd | Enter,
1939
1911
  when: FocusFindWidgetReplace$1
1940
1912
  }, {
1941
- key: Tab,
1942
1913
  command: 'FindWidget.focusNextMatchButton',
1914
+ key: Tab,
1943
1915
  when: FocusFindWidgetPreviousMatchButton
1944
1916
  }, {
1945
- key: Shift | Tab,
1946
1917
  command: 'FindWidget.focusReplace',
1918
+ key: Shift | Tab,
1947
1919
  when: FocusFindWidgetPreviousMatchButton
1948
1920
  }, {
1949
- key: Shift | Tab,
1950
1921
  command: 'FindWidget.focusPreviousMatchButton',
1922
+ key: Shift | Tab,
1951
1923
  when: FocusFindWidgetNextMatchButton
1952
1924
  }, {
1953
- key: Tab,
1954
1925
  command: 'FindWidget.focusCloseButton',
1926
+ key: Tab,
1955
1927
  when: FocusFindWidgetNextMatchButton
1956
1928
  }, {
1957
- key: Shift | Tab,
1958
1929
  command: 'FindWidget.focusNextMatchButton',
1930
+ key: Shift | Tab,
1959
1931
  when: FocusFindWidgetCloseButton$1
1960
1932
  }, {
1961
- key: Tab,
1962
1933
  command: 'FindWidget.focusReplaceButton',
1934
+ key: Tab,
1963
1935
  when: FocusFindWidgetCloseButton$1
1964
1936
  }, {
1965
- key: Shift | Tab,
1966
1937
  command: 'FindWidget.focusFind',
1938
+ key: Shift | Tab,
1967
1939
  when: FocusFindWidgetReplace$1
1968
1940
  }, {
1969
- key: Tab,
1970
1941
  command: 'FindWidget.focusReplaceAllButton',
1942
+ key: Tab,
1971
1943
  when: FocusFindWidgetReplaceButton
1972
1944
  }, {
1973
- key: Shift | Tab,
1974
1945
  command: 'FindWidget.focusCloseButton',
1946
+ key: Shift | Tab,
1975
1947
  when: FocusFindWidgetReplaceButton
1976
1948
  }, {
1977
- key: Shift | Tab,
1978
1949
  command: 'FindWidget.focusReplaceButton',
1950
+ key: Shift | Tab,
1979
1951
  when: FocusFindWidgetReplaceAllButton$1
1980
1952
  }];
1981
1953
  };
@@ -1987,8 +1959,8 @@ const handleInput = (state, value, inputSource = User$1) => {
1987
1959
  const handleReplaceInput = (state, value, inputSource = User$1) => {
1988
1960
  return {
1989
1961
  ...state,
1990
- replacement: value,
1991
- inputSource
1962
+ inputSource,
1963
+ replacement: value
1992
1964
  };
1993
1965
  };
1994
1966
 
@@ -2014,21 +1986,22 @@ const getFindWidgetPosition = (editorX, editorY, editorWidth) => {
2014
1986
  const x = editorX + editorWidth - width - paddingRight;
2015
1987
  const y = editorY + paddingTop;
2016
1988
  return {
2017
- y,
2018
- x,
1989
+ height,
2019
1990
  width,
2020
- height
1991
+ x,
1992
+ y
2021
1993
  };
2022
1994
  };
2023
1995
 
2024
1996
  const getLines = async editorUid => {
2025
- // @ts-ignore
2026
- const lines = await invoke('Editor.getLines2', editorUid);
2027
- // @ts-ignore
1997
+ const lines = await getLines$1(editorUid);
2028
1998
  return lines;
2029
1999
  };
2030
2000
 
2031
2001
  const getSelectedText = (lines, selections) => {
2002
+ if (selections.length === 0) {
2003
+ return '';
2004
+ }
2032
2005
  const startRowIndex = selections[0];
2033
2006
  const startColumnIndex = selections[1];
2034
2007
  const endColumnIndex = selections[3];
@@ -2038,9 +2011,7 @@ const getSelectedText = (lines, selections) => {
2038
2011
  };
2039
2012
 
2040
2013
  const getSelections = async editorUid => {
2041
- // @ts-ignore
2042
- const selections = await invoke('Editor.getSelections2', editorUid);
2043
- // @ts-ignore
2014
+ const selections = await getSelections$1(editorUid);
2044
2015
  return selections;
2045
2016
  };
2046
2017
 
@@ -2060,8 +2031,8 @@ const restoreState = savedState => {
2060
2031
  const value = getSavedValue(savedState);
2061
2032
  const replacement = getSavedReplacement(savedState);
2062
2033
  return {
2063
- value,
2064
- replacement
2034
+ replacement,
2035
+ value
2065
2036
  };
2066
2037
  };
2067
2038
 
@@ -2071,12 +2042,12 @@ const loadContent = async (state, savedState) => {
2071
2042
  editorWidth,
2072
2043
  editorX,
2073
2044
  editorY,
2045
+ inputBorderWidth,
2046
+ inputGap,
2074
2047
  inputLineHeight,
2075
2048
  inputPaddingBottom,
2076
2049
  inputPaddingTop,
2077
- replaceExpanded,
2078
- inputBorderWidth,
2079
- inputGap
2050
+ replaceExpanded
2080
2051
  } = state;
2081
2052
  const {
2082
2053
  replacement,
@@ -2085,9 +2056,9 @@ const loadContent = async (state, savedState) => {
2085
2056
  const lines = await getLines(editorUid);
2086
2057
  const selections = await getSelections(editorUid);
2087
2058
  const {
2059
+ width,
2088
2060
  x,
2089
- y,
2090
- width
2061
+ y
2091
2062
  } = getFindWidgetPosition(editorX, editorY, editorWidth);
2092
2063
  if (lines.length === 0) {
2093
2064
  return state;
@@ -2096,8 +2067,8 @@ const loadContent = async (state, savedState) => {
2096
2067
  const matches = findMatchesCaseInsensitive(lines, actualValue);
2097
2068
  const matchCount = getMatchCount(matches);
2098
2069
  const {
2099
- inputHeight,
2100
- height
2070
+ height,
2071
+ inputHeight
2101
2072
  } = measureInputHeight(value, inputLineHeight, inputPaddingBottom, inputPaddingTop, inputBorderWidth, inputGap, replaceExpanded);
2102
2073
  return {
2103
2074
  ...state,
@@ -2131,33 +2102,33 @@ const SetEventListeners = 'Viewlet.registerEventListeners';
2131
2102
 
2132
2103
  const renderBounds = (oldState, newState) => {
2133
2104
  const {
2134
- x,
2135
- y,
2136
- width,
2137
2105
  height,
2138
- uid
2106
+ uid,
2107
+ width,
2108
+ x,
2109
+ y
2139
2110
  } = newState;
2140
2111
  return [SetBounds, uid, x, y, width, height];
2141
2112
  };
2142
2113
 
2143
- const HandleBlur = 'handleBlur';
2144
- const HandleClickButton = 'handleClickButton';
2145
- const HandleClickClose = 'handleClickClose';
2146
- const HandleClickNextMatch = 'handleClickNextMatch';
2147
- const HandleClickPreviousMatch = 'handleClickPreviousMatch';
2148
- const HandleClickReplace = 'handleClickReplace';
2149
- const HandleClickReplaceAll = 'handleClickReplaceAll';
2150
- const HandleClickToggleReplace = 'handleClickToggleReplace';
2151
- const HandleFocus = 'handleFocus';
2152
- const HandleFocusNext = 'handleFocusNext';
2153
- const HandleFocusPrevious = 'handleFocusPrevious';
2154
- const HandleInput = 'handleInput';
2155
- const HandleReplaceFocus = 'handleReplaceFocus';
2156
- const HandleReplaceInput = 'handleReplaceInput';
2157
- const HandleResizerPointerDown = 'handleResizerPointerDown';
2158
- const HandleResizerPointerMove = 'handleResizerPointerMove';
2159
- const HandleResizerPointerUp = 'handleResizerPointerUp';
2160
- const HandleToggleReplaceFocus = 'handleToggleReplaceFocus';
2114
+ const HandleBlur = 1;
2115
+ const HandleClickButton = 2;
2116
+ const HandleClickClose = 3;
2117
+ const HandleClickNextMatch = 4;
2118
+ const HandleClickPreviousMatch = 5;
2119
+ const HandleClickReplace = 6;
2120
+ const HandleClickReplaceAll = 7;
2121
+ const HandleClickToggleReplace = 8;
2122
+ const HandleFocus = 9;
2123
+ const HandleFocusNext = 10;
2124
+ const HandleFocusPrevious = 11;
2125
+ const HandleInput = 12;
2126
+ const HandleReplaceFocus = 13;
2127
+ const HandleReplaceInput = 14;
2128
+ const HandleResizerPointerDown = 15;
2129
+ const HandleResizerPointerMove = 16;
2130
+ const HandleResizerPointerUp = 17;
2131
+ const HandleToggleReplaceFocus = 19;
2161
2132
 
2162
2133
  const emptyObject = {};
2163
2134
  const RE_PLACEHOLDER = /\{(PH\d+)\}/g;
@@ -2241,60 +2212,60 @@ const getFindWidgetButtons = (findButtonsEnabled, replaceButtonsEnabled, matchCa
2241
2212
  const findFieldButtons = [{
2242
2213
  checked: matchCase$1,
2243
2214
  icon: MatchCase,
2244
- title: matchCase(),
2245
2215
  name: MatchCase$2,
2246
- onClick: HandleClickButton
2216
+ onClick: HandleClickButton,
2217
+ title: matchCase()
2247
2218
  }, {
2248
2219
  checked: matchWholeWord$1,
2249
2220
  icon: MatchWholeWord,
2250
- title: matchWholeWord(),
2251
2221
  name: MatchWholeWord$2,
2252
- onClick: HandleClickButton
2222
+ onClick: HandleClickButton,
2223
+ title: matchWholeWord()
2253
2224
  }, {
2254
2225
  checked: useRegularExpression$1,
2255
2226
  icon: UseRegularExpression,
2256
- title: useRegularExpression(),
2257
2227
  name: UseRegularExpression$2,
2258
- onClick: HandleClickButton
2228
+ onClick: HandleClickButton,
2229
+ title: useRegularExpression()
2259
2230
  }];
2260
2231
  const replaceFieldButtons = [{
2261
2232
  checked: preserveCase$1,
2262
2233
  icon: 'PreserveCase',
2263
- title: preserveCase(),
2264
2234
  name: PreserveCase$1,
2265
- onClick: HandleClickButton
2235
+ onClick: HandleClickButton,
2236
+ title: preserveCase()
2266
2237
  }];
2267
2238
  const findButtons = [{
2268
- label: previousMatch(),
2269
- icon: ArrowUp,
2270
2239
  disabled: !findButtonsEnabled,
2271
- onClick: HandleClickPreviousMatch,
2272
- name: FocusPrevious
2240
+ icon: ArrowUp,
2241
+ label: previousMatch(),
2242
+ name: FocusPrevious,
2243
+ onClick: HandleClickPreviousMatch
2273
2244
  }, {
2274
- label: nextMatch(),
2275
- icon: ArrowDown,
2276
2245
  disabled: !findButtonsEnabled,
2277
- onClick: HandleClickNextMatch,
2278
- name: FocusNext
2246
+ icon: ArrowDown,
2247
+ label: nextMatch(),
2248
+ name: FocusNext,
2249
+ onClick: HandleClickNextMatch
2279
2250
  }, {
2280
- label: close(),
2281
- icon: Close,
2282
2251
  disabled: false,
2283
- onClick: HandleClickClose,
2284
- name: Close$2
2252
+ icon: Close,
2253
+ label: close(),
2254
+ name: Close$2,
2255
+ onClick: HandleClickClose
2285
2256
  }];
2286
2257
  const replaceButtons = [{
2287
- label: replace(),
2288
- icon: Replace,
2289
2258
  disabled: !replaceButtonsEnabled,
2290
- onClick: HandleClickButton,
2291
- name: Replace$2
2259
+ icon: Replace,
2260
+ label: replace(),
2261
+ name: Replace$2,
2262
+ onClick: HandleClickButton
2292
2263
  }, {
2293
- label: replaceAll(),
2294
- icon: ReplaceAll,
2295
2264
  disabled: !replaceButtonsEnabled,
2296
- onClick: HandleClickButton,
2297
- name: ReplaceAll$2
2265
+ icon: ReplaceAll,
2266
+ label: replaceAll(),
2267
+ name: ReplaceAll$2,
2268
+ onClick: HandleClickButton
2298
2269
  }];
2299
2270
  return {
2300
2271
  findButtons,
@@ -2313,6 +2284,15 @@ const getFindWidgetButtonsEnabled = (matchCount, value) => {
2313
2284
  };
2314
2285
  };
2315
2286
 
2287
+ const CheckBox = 'checkbox';
2288
+ const Group = 'group';
2289
+ const None = 'none';
2290
+
2291
+ const Button = 1;
2292
+ const Div = 4;
2293
+ const Text = 12;
2294
+ const TextArea = 62;
2295
+
2316
2296
  const mergeClassNames = (...classNames) => {
2317
2297
  return classNames.filter(Boolean).join(' ');
2318
2298
  };
@@ -2353,18 +2333,18 @@ const ViewletFindWidget = 'ViewletFindWidget';
2353
2333
 
2354
2334
  const getIconVirtualDom = (icon, type = Div) => {
2355
2335
  return {
2356
- type,
2336
+ childCount: 0,
2357
2337
  className: `${MaskIcon} MaskIcon${icon}`,
2358
2338
  role: None,
2359
- childCount: 0
2339
+ type
2360
2340
  };
2361
2341
  };
2362
2342
 
2363
2343
  const getIconButtonVirtualDom = iconButton => {
2364
2344
  const {
2365
- label,
2366
- icon,
2367
2345
  disabled,
2346
+ icon,
2347
+ label,
2368
2348
  name,
2369
2349
  onClick
2370
2350
  } = iconButton;
@@ -2373,14 +2353,14 @@ const getIconButtonVirtualDom = iconButton => {
2373
2353
  className += ' ' + IconButtonDisabled;
2374
2354
  }
2375
2355
  return [{
2376
- type: Button,
2377
- className,
2378
- title: label,
2379
2356
  ariaLabel: label,
2380
2357
  childCount: 1,
2358
+ className,
2381
2359
  disabled: disabled ? true : undefined,
2360
+ name,
2382
2361
  onClick,
2383
- name
2362
+ title: label,
2363
+ type: Button
2384
2364
  }, getIconVirtualDom(icon)];
2385
2365
  };
2386
2366
 
@@ -2394,9 +2374,9 @@ const getFindMatchCountClassName = (matchCount, hasValue) => {
2394
2374
 
2395
2375
  const getMatchCountVirtualDom = (matchCountText, matchCount, hasValue) => {
2396
2376
  return [{
2397
- type: Div,
2377
+ childCount: 1,
2398
2378
  className: getFindMatchCountClassName(matchCount, hasValue),
2399
- childCount: 1
2379
+ type: Div
2400
2380
  }, text(matchCountText)];
2401
2381
  };
2402
2382
 
@@ -2404,50 +2384,50 @@ const checkedClassName = mergeClassNames(SearchFieldButton, SearchFieldButtonChe
2404
2384
  const unCheckedClassName = SearchFieldButton;
2405
2385
  const getSearchFieldButtonVirtualDom = button => {
2406
2386
  const {
2407
- icon,
2408
2387
  checked,
2409
- title,
2388
+ icon,
2410
2389
  name,
2411
- onClick
2390
+ onClick,
2391
+ title
2412
2392
  } = button;
2413
2393
  return [{
2414
- type: Button,
2415
2394
  ariaChecked: checked,
2395
+ childCount: 1,
2416
2396
  className: checked ? checkedClassName : unCheckedClassName,
2417
2397
  name,
2398
+ onClick,
2418
2399
  role: CheckBox,
2419
2400
  tabIndex: 0,
2420
2401
  title,
2421
- childCount: 1,
2422
- onClick
2402
+ type: Button
2423
2403
  }, {
2424
- type: Div,
2404
+ childCount: 0,
2425
2405
  className: mergeClassNames(MaskIcon, `MaskIcon${icon}`),
2426
- childCount: 0
2406
+ type: Div
2427
2407
  }];
2428
2408
  };
2429
2409
 
2430
2410
  const getSearchFieldVirtualDom = (name, placeholder, onInput, insideButtons, outsideButtons, onFocus, extraClassName) => {
2431
2411
  const dom = [{
2432
- type: Div,
2412
+ childCount: 2,
2433
2413
  className: mergeClassNames(SearchField, extraClassName),
2434
2414
  role: None,
2435
- childCount: 2
2415
+ type: Div
2436
2416
  }, {
2437
- type: TextArea,
2438
- className: MultilineInputBox,
2439
- spellcheck: false,
2440
2417
  autocapitalize: 'off',
2441
2418
  autocorrect: 'off',
2442
- placeholder,
2419
+ childCount: 0,
2420
+ className: MultilineInputBox,
2443
2421
  name,
2444
- onInput,
2445
2422
  onFocus,
2446
- childCount: 0
2423
+ onInput,
2424
+ placeholder,
2425
+ spellcheck: false,
2426
+ type: TextArea
2447
2427
  }, {
2448
- type: Div,
2428
+ childCount: insideButtons.length,
2449
2429
  className: SearchFieldButtons,
2450
- childCount: insideButtons.length
2430
+ type: Div
2451
2431
  }, ...insideButtons.flatMap(getSearchFieldButtonVirtualDom)];
2452
2432
  if (outsideButtons.length > 0) {
2453
2433
  throw new Error('outsideButtons are deprecated');
@@ -2467,13 +2447,13 @@ const getExtraClassName = (hasError, inputFocused) => {
2467
2447
  const getFindWidgetFindVirtualDom = (matchCountText, buttons, fieldButtons, matchCount, hasValue, hasError, inputFocused) => {
2468
2448
  const extraClassName = getExtraClassName(hasError, inputFocused);
2469
2449
  return [{
2470
- type: Div,
2450
+ childCount: 2,
2471
2451
  className: FindWidgetFind,
2472
- childCount: 2
2452
+ type: Div
2473
2453
  }, ...getSearchFieldVirtualDom(SearchValue, find(), HandleInput, fieldButtons, [], HandleFocus, extraClassName), {
2474
- type: Div,
2454
+ childCount: 1 + buttons.length,
2475
2455
  className: 'FindWidgetActions',
2476
- childCount: 1 + buttons.length
2456
+ type: Div
2477
2457
  }, ...getMatchCountVirtualDom(matchCountText, matchCount, hasValue), ...buttons.flatMap(getIconButtonVirtualDom)];
2478
2458
  };
2479
2459
 
@@ -2483,56 +2463,56 @@ const getFindWidgetReplaceVirtualDom = (replaceExpanded, replaceButtons, replace
2483
2463
  }
2484
2464
  const extraClassName = replaceInputFocused ? SearchFieldFocused : '';
2485
2465
  return [{
2486
- type: Div,
2466
+ childCount: 1 + replaceButtons.length,
2487
2467
  className: FindWidgetReplace,
2488
- childCount: 1 + replaceButtons.length
2468
+ type: Div
2489
2469
  }, ...getSearchFieldVirtualDom(ReplaceValue, replace(), HandleReplaceInput, [], [], HandleReplaceFocus, extraClassName), ...replaceButtons.flatMap(getIconButtonVirtualDom)];
2490
2470
  };
2491
2471
 
2492
2472
  const getResizerVirtualDom = () => {
2493
2473
  return [{
2494
- type: Div,
2495
- className: Resizer,
2496
2474
  childCount: 1,
2497
- onPointerDown: HandleResizerPointerDown
2475
+ className: Resizer,
2476
+ onPointerDown: HandleResizerPointerDown,
2477
+ type: Div
2498
2478
  }, {
2499
- type: Div,
2479
+ childCount: 0,
2500
2480
  className: ResizerHighlight,
2501
- childCount: 0
2481
+ type: Div
2502
2482
  }];
2503
2483
  };
2504
2484
 
2505
2485
  const getSearchToggleButtonVirtualDom = (replaceExpanded, onClick = '') => {
2506
2486
  const title = toggleReplace();
2507
2487
  return [{
2508
- type: Button,
2509
- className: mergeClassNames(IconButton, SearchToggleButton, replaceExpanded ? SearchToggleButtonExpanded : ''),
2510
- title,
2511
- ariaLabel: title,
2512
2488
  ariaExpanded: replaceExpanded,
2513
- name: ToggleReplace$1,
2489
+ ariaLabel: title,
2514
2490
  childCount: 1,
2491
+ className: mergeClassNames(IconButton, SearchToggleButton, replaceExpanded ? SearchToggleButtonExpanded : ''),
2515
2492
  'data-command': 'toggleReplace',
2493
+ name: ToggleReplace$1,
2516
2494
  onClick,
2517
- onFocus: HandleToggleReplaceFocus
2495
+ onFocus: HandleToggleReplaceFocus,
2496
+ title,
2497
+ type: Button
2518
2498
  }, {
2519
- type: Div,
2499
+ childCount: 0,
2520
2500
  className: mergeClassNames(MaskIcon, replaceExpanded ? MaskIconChevronDown : MaskIconChevronRight),
2521
- childCount: 0
2501
+ type: Div
2522
2502
  }];
2523
2503
  };
2524
2504
 
2525
2505
  const parentNode = {
2526
- type: Div,
2527
- className: mergeClassNames(Viewlet, ViewletFind, ViewletFindWidget, FindWidget),
2528
2506
  childCount: 3,
2529
- role: Group
2507
+ className: mergeClassNames(Viewlet, ViewletFind, ViewletFindWidget, FindWidget),
2508
+ role: Group,
2509
+ type: Div
2530
2510
  };
2531
2511
  const getFindWidgetVirtualDom = (matchCountText, replaceExpanded, findButtons, findFieldButtons, replaceButtons, replaceFieldButtons, matchCount, value, hasError, inputFocused, replaceInputFocused) => {
2532
2512
  return [parentNode, ...getResizerVirtualDom(), ...getSearchToggleButtonVirtualDom(replaceExpanded, 'handleClickToggleReplace'), {
2533
- type: Div,
2513
+ childCount: replaceExpanded ? 2 : 1,
2534
2514
  className: FindWidgetRight,
2535
- childCount: replaceExpanded ? 2 : 1
2515
+ type: Div
2536
2516
  }, ...getFindWidgetFindVirtualDom(matchCountText, findButtons, findFieldButtons, matchCount, Boolean(value), hasError, inputFocused), ...getFindWidgetReplaceVirtualDom(replaceExpanded, replaceButtons, replaceFieldButtons, replaceInputFocused)];
2537
2517
  };
2538
2518
 
@@ -2546,15 +2526,15 @@ const getMatchCountText = (matchIndex, matchCount) => {
2546
2526
  const renderContent = (oldState, newState) => {
2547
2527
  const {
2548
2528
  focus,
2549
- uid,
2550
- matchCount,
2551
- value,
2552
- replaceExpanded,
2529
+ inputErrorMessage,
2553
2530
  matchCase,
2531
+ matchCount,
2554
2532
  matchWholeWord,
2555
- useRegularExpression,
2556
2533
  preserveCase,
2557
- inputErrorMessage
2534
+ replaceExpanded,
2535
+ uid,
2536
+ useRegularExpression,
2537
+ value
2558
2538
  } = newState;
2559
2539
  const matchCountText = getMatchCountText(newState.matchIndex, newState.matchCount);
2560
2540
  const {
@@ -2563,8 +2543,8 @@ const renderContent = (oldState, newState) => {
2563
2543
  } = getFindWidgetButtonsEnabled(matchCount, value);
2564
2544
  const {
2565
2545
  findButtons,
2566
- replaceButtons,
2567
2546
  findFieldButtons,
2547
+ replaceButtons,
2568
2548
  replaceFieldButtons
2569
2549
  } = getFindWidgetButtons(findButtonsEnabled, replaceButtonsEnabled, matchCase, matchWholeWord, useRegularExpression, preserveCase);
2570
2550
  const hasError = Boolean(inputErrorMessage);
@@ -2576,12 +2556,12 @@ const renderContent = (oldState, newState) => {
2576
2556
 
2577
2557
  const renderCss = (oldState, newState) => {
2578
2558
  const {
2559
+ height,
2560
+ searchInputHeight: inputHeight,
2579
2561
  uid,
2580
2562
  width,
2581
- height,
2582
2563
  x,
2583
- y,
2584
- searchInputHeight: inputHeight
2564
+ y
2585
2565
  } = newState;
2586
2566
  const css = `:root {
2587
2567
  --FindWidgetWidth: ${width}px;
@@ -2596,7 +2576,7 @@ const renderCss = (oldState, newState) => {
2596
2576
  const getEventListeners = (uid, widgetId) => {
2597
2577
  return [{
2598
2578
  name: HandleInput,
2599
- params: ['executeWidgetCommand', 'FindWidget', 'FindWidget.handleInput', 0, widgetId, 'event.target.value']
2579
+ params: ['executeWidgetCommand', 'FindWidget', 'FindWidget.handleInput', 0, widgetId, TargetValue]
2600
2580
  }, {
2601
2581
  name: HandleClickClose,
2602
2582
  params: ['executeWidgetCommand', 'FindWidget', 'FindWidget.handleClickClose', 0, widgetId]
@@ -2620,7 +2600,7 @@ const getEventListeners = (uid, widgetId) => {
2620
2600
  params: ['executeWidgetCommand', 'FindWidget', 'FindWidget.handleBlur', 0, widgetId]
2621
2601
  }, {
2622
2602
  name: HandleReplaceInput,
2623
- params: ['executeWidgetCommand', 'FindWidget', 'FindWidget.handleReplaceInput', 0, widgetId]
2603
+ params: ['executeWidgetCommand', 'FindWidget', 'FindWidget.handleReplaceInput', 0, widgetId, TargetValue]
2624
2604
  }, {
2625
2605
  name: HandleReplaceFocus,
2626
2606
  params: ['executeWidgetCommand', 'FindWidget', 'FindWidget.handleReplaceFocus', 0, widgetId]
@@ -2630,6 +2610,9 @@ const getEventListeners = (uid, widgetId) => {
2630
2610
  }, {
2631
2611
  name: HandleFocusNext,
2632
2612
  params: ['executeWidgetCommand', 'FindWidget', 'FindWidget.handleFocusNext', 0, widgetId]
2613
+ }, {
2614
+ name: HandleToggleReplaceFocus,
2615
+ params: ['executeWidgetCommand', 'FindWidget', 'FindWidget.handleToggleReplaceFocus', 0, widgetId]
2633
2616
  }, {
2634
2617
  name: HandleClickReplaceAll,
2635
2618
  params: ['executeWidgetCommand', 'FindWidget', 'FindWidget.handleClickReplaceAll', 0, widgetId]
@@ -2661,24 +2644,24 @@ const renderEventListeners = state => {
2661
2644
 
2662
2645
  const getFocusSelector = focusKey => {
2663
2646
  switch (focusKey) {
2647
+ case FocusFindWidgetCloseButton$1:
2648
+ return Close$2;
2664
2649
  case FocusSearchInput:
2665
2650
  return SearchValue;
2666
- case FocusSearchReplaceInput:
2667
- return ReplaceValue;
2668
2651
  case FocusSearchMatchCase:
2669
2652
  return MatchCase$2;
2670
2653
  case FocusSearchPreserveCase:
2671
2654
  return PreserveCase$1;
2672
2655
  case FocusSearchRegex:
2673
2656
  return UseRegularExpression$2;
2674
- case FocusSearchWholeWord:
2675
- return MatchWholeWord$2;
2676
2657
  case FocusSearchReplaceAll:
2677
2658
  return ReplaceAll$2;
2659
+ case FocusSearchReplaceInput:
2660
+ return ReplaceValue;
2661
+ case FocusSearchWholeWord:
2662
+ return MatchWholeWord$2;
2678
2663
  case FocusToggleReplace:
2679
2664
  return ToggleReplace$1;
2680
- case FocusFindWidgetCloseButton$1:
2681
- return Close$2;
2682
2665
  default:
2683
2666
  return '';
2684
2667
  }
@@ -2686,8 +2669,8 @@ const getFocusSelector = focusKey => {
2686
2669
 
2687
2670
  const renderFocus = (oldState, newState) => {
2688
2671
  const {
2689
- uid,
2690
- focus
2672
+ focus,
2673
+ uid
2691
2674
  } = newState;
2692
2675
  const name = getFocusSelector(focus);
2693
2676
  const selector = `[name="${name}"]`;
@@ -2702,16 +2685,16 @@ const renderFocusContext = (oldState, newState) => {
2702
2685
 
2703
2686
  const renderReplaceValue = (oldState, newState) => {
2704
2687
  const {
2705
- uid,
2706
- replacement
2688
+ replacement,
2689
+ uid
2707
2690
  } = newState;
2708
2691
  return [SetValueByName, uid, ReplaceValue, replacement];
2709
2692
  };
2710
2693
 
2711
2694
  const renderUid = (oldState, newState) => {
2712
2695
  const {
2713
- uid,
2714
- editorUid
2696
+ editorUid,
2697
+ uid
2715
2698
  } = newState;
2716
2699
  return [SetUid, uid, editorUid];
2717
2700
  };
@@ -2726,24 +2709,24 @@ const renderValue = (oldState, newState) => {
2726
2709
 
2727
2710
  const getRenderer = diffType => {
2728
2711
  switch (diffType) {
2729
- case RenderContent:
2730
- return renderContent;
2731
2712
  case RenderBounds:
2732
2713
  return renderBounds;
2714
+ case RenderContent:
2715
+ return renderContent;
2716
+ case RenderCss:
2717
+ return renderCss;
2733
2718
  case RenderEventListeners:
2734
2719
  return renderEventListeners;
2735
- case RenderUid:
2736
- return renderUid;
2737
- case RenderFocusContext:
2738
- return renderFocusContext;
2739
2720
  case RenderFocus:
2740
2721
  return renderFocus;
2741
- case RenderValue:
2742
- return renderValue;
2722
+ case RenderFocusContext:
2723
+ return renderFocusContext;
2743
2724
  case RenderReplaceValue:
2744
2725
  return renderReplaceValue;
2745
- case RenderCss:
2746
- return renderCss;
2726
+ case RenderUid:
2727
+ return renderUid;
2728
+ case RenderValue:
2729
+ return renderValue;
2747
2730
  default:
2748
2731
  throw new Error('unknown renderer');
2749
2732
  }
@@ -2760,8 +2743,8 @@ const applyRender = (oldState, newState, diffResult) => {
2760
2743
 
2761
2744
  const render2 = (uid, diffResult) => {
2762
2745
  const {
2763
- oldState,
2764
- newState
2746
+ newState,
2747
+ oldState
2765
2748
  } = get(uid);
2766
2749
  set(uid, newState, newState);
2767
2750
  const commands = applyRender(oldState, newState, diffResult);
@@ -2774,29 +2757,29 @@ const resize = async (state, dimensions) => {
2774
2757
 
2775
2758
  const saveState = state => {
2776
2759
  const {
2777
- width,
2778
- value,
2779
- replacement,
2780
2760
  matchCase,
2781
2761
  matchWholeWord,
2762
+ replaceExpanded,
2763
+ replacement,
2782
2764
  useRegularExpression,
2783
- replaceExpanded
2765
+ value,
2766
+ width
2784
2767
  } = state;
2785
2768
  return {
2786
- width,
2787
- value,
2788
- replacement,
2789
2769
  matchCase,
2790
2770
  matchWholeWord,
2771
+ replaceExpanded,
2772
+ replacement,
2791
2773
  useRegularExpression,
2792
- replaceExpanded
2774
+ value,
2775
+ width
2793
2776
  };
2794
2777
  };
2795
2778
 
2796
2779
  const commandMap = {
2780
+ 'FindWidget.close': wrapCommand(close$1),
2797
2781
  'FindWidget.create': create,
2798
2782
  'FindWidget.diff2': diff2,
2799
- 'FindWidget.close': wrapCommand(close$1),
2800
2783
  'FindWidget.dispose': dispose,
2801
2784
  'FindWidget.focusCloseButton': wrapCommand(focusCloseButton),
2802
2785
  'FindWidget.focusElement': wrapCommand(focusElement),
@@ -2814,12 +2797,14 @@ const commandMap = {
2814
2797
  'FindWidget.handleBlur': wrapCommand(handleBlur),
2815
2798
  'FindWidget.handleClickButton': wrapCommand(handleClickButton),
2816
2799
  'FindWidget.handleClickClose': wrapCommand(handleClickClose),
2800
+ 'FindWidget.handleFocus': wrapCommand(handleFindFocus),
2817
2801
  'FindWidget.handleInput': wrapCommand(handleInput),
2818
2802
  'FindWidget.handleReplaceFocus': wrapCommand(handleReplaceFocus),
2819
2803
  'FindWidget.handleReplaceInput': wrapCommand(handleReplaceInput),
2820
2804
  'FindWidget.handleResizerPointerDown': wrapCommand(handleResizerPointerDown),
2821
2805
  'FindWidget.handleResizerPointerMove': wrapCommand(handleResizerPointerMove),
2822
2806
  'FindWidget.handleResizerPointerUp': wrapCommand(handleResizerPointerUp),
2807
+ 'FindWidget.handleToggleReplaceFocus': wrapCommand(handleToggleReplaceFocus),
2823
2808
  'FindWidget.loadContent': wrapCommand(loadContent),
2824
2809
  'FindWidget.preventDefaultBrowserFind': wrapCommand(preventDefaultBrowserFind),
2825
2810
  'FindWidget.render2': render2,
@@ -2829,10 +2814,10 @@ const commandMap = {
2829
2814
  'FindWidget.saveState': wrapGetter(saveState),
2830
2815
  'FindWidget.terminate': terminate,
2831
2816
  'FindWidget.toggleMatchCase': wrapCommand(toggleMatchCase),
2832
- 'FindWidget.toggleReplace': wrapCommand(toggleReplace$1),
2833
- 'FindWidget.toggleUseRegularExpression': wrapCommand(toggleUseRegularExpression),
2817
+ 'FindWidget.toggleMatchWholeWord': wrapCommand(toggleMatchWholeWord),
2834
2818
  'FindWidget.togglePreserveCase': wrapCommand(togglePreserveCase),
2835
- 'FindWidget.toggleMatchWholeWord': wrapCommand(toggleMatchWholeWord)
2819
+ 'FindWidget.toggleReplace': wrapCommand(toggleReplace$1),
2820
+ 'FindWidget.toggleUseRegularExpression': wrapCommand(toggleUseRegularExpression)
2836
2821
  };
2837
2822
 
2838
2823
  const listen = async () => {