@lvce-editor/explorer-view 1.0.0 → 1.1.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.
@@ -1095,6 +1095,101 @@ const expandAll = async state => {
1095
1095
  };
1096
1096
  };
1097
1097
 
1098
+ const focusIndex = (state, index) => {
1099
+ const {
1100
+ minLineY,
1101
+ maxLineY
1102
+ } = state;
1103
+ if (index < minLineY) {
1104
+ if (index < 0) {
1105
+ return {
1106
+ ...state,
1107
+ focusedIndex: index,
1108
+ focused: true
1109
+ };
1110
+ }
1111
+ const diff = maxLineY - minLineY;
1112
+ return {
1113
+ ...state,
1114
+ focusedIndex: index,
1115
+ focused: true,
1116
+ minLineY: index,
1117
+ maxLineY: index + diff
1118
+ };
1119
+ }
1120
+ if (index >= maxLineY) {
1121
+ const diff = maxLineY - minLineY;
1122
+ return {
1123
+ ...state,
1124
+ focusedIndex: index,
1125
+ focused: true,
1126
+ minLineY: index + 1 - diff,
1127
+ maxLineY: index + 1
1128
+ };
1129
+ }
1130
+ return {
1131
+ ...state,
1132
+ focusedIndex: index,
1133
+ focused: true
1134
+ };
1135
+ };
1136
+
1137
+ const focusFirst = state => {
1138
+ const {
1139
+ focusedIndex,
1140
+ items
1141
+ } = state;
1142
+ if (items.length === 0 || focusedIndex === 0) {
1143
+ return state;
1144
+ }
1145
+ return focusIndex(state, 0);
1146
+ };
1147
+
1148
+ const lastIndex = array => {
1149
+ return array.length - 1;
1150
+ };
1151
+
1152
+ const focusLast = state => {
1153
+ const {
1154
+ focusedIndex,
1155
+ items
1156
+ } = state;
1157
+ const lastIndex$1 = lastIndex(items);
1158
+ if (items.length === 0 || focusedIndex === lastIndex$1) {
1159
+ return state;
1160
+ }
1161
+ return focusIndex(state, lastIndex$1);
1162
+ };
1163
+
1164
+ const focusNext = state => {
1165
+ const {
1166
+ focusedIndex,
1167
+ items
1168
+ } = state;
1169
+ if (focusedIndex === lastIndex(items)) {
1170
+ return state;
1171
+ }
1172
+ return focusIndex(state, focusedIndex + 1);
1173
+ };
1174
+
1175
+ const focusPrevious = state => {
1176
+ const {
1177
+ focusedIndex,
1178
+ items
1179
+ } = state;
1180
+ switch (focusedIndex) {
1181
+ case -1:
1182
+ if (items.length === 0) {
1183
+ return state;
1184
+ }
1185
+ return focusIndex(state, lastIndex(items));
1186
+ case 0:
1187
+ return state;
1188
+ default:
1189
+ return focusIndex(state, focusedIndex - 1);
1190
+ }
1191
+ };
1192
+
1098
1193
  const None$1 = 'none';
1099
1194
  const Tree = 'tree';
1100
1195
  const TreeItem$1 = 'treeitem';
@@ -1497,45 +1592,6 @@ const getVisibleExplorerItems = (items, minLineY, maxLineY, focusedIndex, editin
1497
1592
  return visible;
1498
1593
  };
1499
1594
 
1500
- const focusIndex = (state, index) => {
1501
- const {
1502
- minLineY,
1503
- maxLineY
1504
- } = state;
1505
- if (index < minLineY) {
1506
- if (index < 0) {
1507
- return {
1508
- ...state,
1509
- focusedIndex: index,
1510
- focused: true
1511
- };
1512
- }
1513
- const diff = maxLineY - minLineY;
1514
- return {
1515
- ...state,
1516
- focusedIndex: index,
1517
- focused: true,
1518
- minLineY: index,
1519
- maxLineY: index + diff
1520
- };
1521
- }
1522
- if (index >= maxLineY) {
1523
- const diff = maxLineY - minLineY;
1524
- return {
1525
- ...state,
1526
- focusedIndex: index,
1527
- focused: true,
1528
- minLineY: index + 1 - diff,
1529
- maxLineY: index + 1
1530
- };
1531
- }
1532
- return {
1533
- ...state,
1534
- focusedIndex: index,
1535
- focused: true
1536
- };
1537
- };
1538
-
1539
1595
  const LeftClick = 0;
1540
1596
 
1541
1597
  const openFolder = async () => {
@@ -2013,6 +2069,11 @@ const commandMap = {
2013
2069
  'Explorer.copyPath': copyPath,
2014
2070
  'Explorer.copyRelativePath': copyRelativePath,
2015
2071
  'Explorer.expandAll': expandAll,
2072
+ 'Explorer.focusFirst': focusFirst,
2073
+ 'Explorer.focusIndex': focusIndex,
2074
+ 'Explorer.focusLast': focusLast,
2075
+ 'Explorer.focusNext': focusNext,
2076
+ 'Explorer.focusPrevious': focusPrevious,
2016
2077
  'Explorer.getKeyBindings': getKeyBindings,
2017
2078
  'Explorer.getVirtualDom': getExplorerVirtualDom,
2018
2079
  'Explorer.getVisibleItems': getVisibleExplorerItems,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/explorer-view",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Explorer Worker",
5
5
  "main": "dist/explorerViewWorkerMain.js",
6
6
  "type": "module",