@aochuang/client-sdk 1.0.298 → 1.0.299

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.
@@ -243,9 +243,10 @@ export default {
243
243
  const cursorPos = this.cacheInputRange ? this.cacheInputRange.start : 0
244
244
  const nearsetInfo = getNearestString(inputValue, cursorPos)
245
245
  this.suggestionsNearsetInfo = nearsetInfo
246
- const nearest = (nearsetInfo.nearest || '').trim()
246
+ const nearest = this.normalizeSuggestionsKeyword(nearsetInfo)
247
247
  if (!nearest) {
248
248
  this.closeSuggestions()
249
+ return
249
250
  }
250
251
  this.loadSuggestions(nearest, nearsetInfo)
251
252
  }, 200)
@@ -254,7 +255,7 @@ export default {
254
255
  if (!this.fetchSuggestionsMethod) {
255
256
  return
256
257
  }
257
- keyword = keyword.trim()
258
+ keyword = this.normalizeSuggestionsKeyword(nearestInfo, keyword)
258
259
  this.suggestioning = true
259
260
  this.suggestionsKeyword = keyword
260
261
  clearTimeout(this._loadSuggestionsTimer)
@@ -268,6 +269,14 @@ export default {
268
269
  this.suggestioning = false
269
270
  })
270
271
  },
272
+ normalizeSuggestionsKeyword (nearestInfo, keyword) {
273
+ const nearest = keyword === undefined
274
+ ? (nearestInfo && nearestInfo.nearest) || ''
275
+ : keyword || ''
276
+ return nearestInfo && nearestInfo.isAtContext
277
+ ? nearest.trim()
278
+ : nearest.replace(/^\s+/, '')
279
+ },
271
280
  closeSuggestions () {
272
281
  this.$refs.suggestions && this.$refs.suggestions.close()
273
282
  },
@@ -38,19 +38,33 @@ export function getNearestString (inputStr, cursorPos) {
38
38
  break;
39
39
  }
40
40
  }
41
+
42
+ if (!isAtContext) {
43
+ let wordCursor = safeCursorPos - 1;
44
+ while (wordCursor >= 0 && /\s/.test(inputStr[wordCursor])) {
45
+ wordCursor--;
46
+ }
47
+ if (wordCursor < 0) {
48
+ return { nearest: '', start: safeCursorPos, end: safeCursorPos, isAtContext: false };
49
+ }
50
+ let start = wordCursor;
51
+ while (start > 0 && !/\s/.test(inputStr[start - 1])) {
52
+ start--;
53
+ }
54
+ return {
55
+ nearest: inputStr.slice(start, safeCursorPos),
56
+ start,
57
+ end: safeCursorPos,
58
+ isAtContext: false
59
+ };
60
+ }
41
61
 
42
62
  // 2. 根据上下文选择拆分模式
43
63
  let splitRegex, isSeparator;
44
64
 
45
- if (isAtContext) {
46
- // @ 成员场景:按 @ 字符拆分
47
- splitRegex = /(@)/;
48
- isSeparator = (part) => part === '@';
49
- } else {
50
- // 普通输入场景:按空白字符拆分
51
- splitRegex = /(\s+)/;
52
- isSeparator = (part) => /\s+/.test(part);
53
- }
65
+ // @ 成员场景:按 @ 字符拆分
66
+ splitRegex = /(@)/;
67
+ isSeparator = (part) => part === '@';
54
68
 
55
69
  // 拆分字符串(保留分隔符,用于定位)
56
70
  const parts = inputStr.split(splitRegex);
@@ -186,4 +200,4 @@ export function getNearestString (inputStr, cursorPos) {
186
200
  }
187
201
  }
188
202
  return { nearest, start, end, isAtContext };
189
- }
203
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aochuang/client-sdk",
3
- "version": "1.0.298",
3
+ "version": "1.0.299",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"