toolcraft 0.0.169 → 0.0.170

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/composition.json CHANGED
@@ -113,7 +113,7 @@
113
113
  },
114
114
  {
115
115
  "name": "toolcraft",
116
- "version": "0.0.169",
116
+ "version": "0.0.170",
117
117
  "license": "MIT"
118
118
  },
119
119
  {
@@ -123,7 +123,7 @@
123
123
  },
124
124
  {
125
125
  "name": "toolcraft-schema",
126
- "version": "0.0.169",
126
+ "version": "0.0.170",
127
127
  "license": "MIT"
128
128
  },
129
129
  {
@@ -113,7 +113,7 @@
113
113
  },
114
114
  {
115
115
  "name": "toolcraft",
116
- "version": "0.0.169",
116
+ "version": "0.0.170",
117
117
  "license": "MIT"
118
118
  },
119
119
  {
@@ -123,7 +123,7 @@
123
123
  },
124
124
  {
125
125
  "name": "toolcraft-schema",
126
- "version": "0.0.169",
126
+ "version": "0.0.170",
127
127
  "license": "MIT"
128
128
  },
129
129
  {
@@ -8,7 +8,7 @@
8
8
  },
9
9
  {
10
10
  "name": "toolcraft-schema",
11
- "version": "0.0.169",
11
+ "version": "0.0.170",
12
12
  "license": "MIT"
13
13
  }
14
14
  ]
@@ -1,3 +1,4 @@
1
+ import { graphemes } from "../dashboard/terminal-width.js";
1
2
  const MATCH_SCORE = 10;
2
3
  const CONSECUTIVE_BONUS = 14;
3
4
  const WORD_START_BONUS = 10;
@@ -13,7 +14,11 @@ export function filterRows(query, rows, opts = {}) {
13
14
  const preparedText = opts.caseSensitive === true ? text : text.toLocaleLowerCase();
14
15
  const match = matchSubsequence(preparedQuery, preparedText);
15
16
  if (match !== undefined) {
16
- matches.push({ index, ...match });
17
+ matches.push({
18
+ index,
19
+ ...match,
20
+ positions: text === preparedText ? match.positions : projectPositions(text, match.positions)
21
+ });
17
22
  }
18
23
  });
19
24
  return matches.sort((left, right) => right.score - left.score || left.index - right.index);
@@ -27,6 +32,33 @@ function searchableText(row) {
27
32
  function stripAnsi(value) {
28
33
  return value.replace(/\u001b\[[0-9;]*m/g, "");
29
34
  }
35
+ function projectPositions(text, positions) {
36
+ const projected = [];
37
+ let originalOffset = 0;
38
+ let foldedOffset = 0;
39
+ let matchIndex = 0;
40
+ for (const segment of graphemes(text)) {
41
+ const foldedLength = segment.toLocaleLowerCase().length;
42
+ const firstMatch = matchIndex;
43
+ while (matchIndex < positions.length && positions[matchIndex] < foldedOffset + foldedLength) {
44
+ if (segment.length === foldedLength) {
45
+ projected.push(originalOffset + positions[matchIndex] - foldedOffset);
46
+ }
47
+ matchIndex += 1;
48
+ }
49
+ if (matchIndex > firstMatch && segment.length !== foldedLength) {
50
+ for (let offset = 0; offset < segment.length; offset += 1) {
51
+ projected.push(originalOffset + offset);
52
+ }
53
+ }
54
+ if (matchIndex === positions.length) {
55
+ break;
56
+ }
57
+ originalOffset += segment.length;
58
+ foldedOffset += foldedLength;
59
+ }
60
+ return projected;
61
+ }
30
62
  function matchSubsequence(query, text) {
31
63
  const queryCharacters = Array.from(query);
32
64
  const textCharacters = Array.from(text);
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "toolcraft-schema",
3
- "version": "0.0.169",
3
+ "version": "0.0.170",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "toolcraft",
3
- "version": "0.0.169",
3
+ "version": "0.0.170",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -158,7 +158,7 @@
158
158
  "yaml"
159
159
  ],
160
160
  "optionalDependencies": {
161
- "toolcraft-schema": "0.0.169",
161
+ "toolcraft-schema": "0.0.170",
162
162
  "toolcraft-design": "*",
163
163
  "@poe-code/frontmatter": "*",
164
164
  "@poe-code/agent-mcp-config": "*",