From e65cbaf0bf897af0dae787f64741ab19ddac166f Mon Sep 17 00:00:00 2001 From: oeyoews Date: Sat, 5 Oct 2024 20:06:31 +0800 Subject: [PATCH] feat: improve inline suggestion(ghost text) --- package.json | 2 +- .../modules/extensions/inlinesuggest.ts | 19 +++++++++++++++---- src/tiddlywiki-codemirror-6/plugin.info | 2 +- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 2d35b5f6..2d537754 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "registry": "https://registry.npmjs.org" }, "license": "MIT", - "version": "2.4.1", + "version": "2.5.0", "packageManager": "pnpm@9.0.6", "scripts": { "update:config": " pnpm ts-node scripts/generateConfig.ts", diff --git a/src/tiddlywiki-codemirror-6/modules/extensions/inlinesuggest.ts b/src/tiddlywiki-codemirror-6/modules/extensions/inlinesuggest.ts index cd73ef5c..04699f5a 100644 --- a/src/tiddlywiki-codemirror-6/modules/extensions/inlinesuggest.ts +++ b/src/tiddlywiki-codemirror-6/modules/extensions/inlinesuggest.ts @@ -5,6 +5,7 @@ import { inlineSuggestion } from '@/cm6/modules/extensions/inlineSuggestion'; import { completionStatus, selectedCompletion } from '@codemirror/autocomplete'; import cm6 from '@/cm6/config'; import { EditorView } from '@codemirror/view'; +import { delimiters } from '../completions/sources'; // @WIP // @see-also: https://github.com/ChromeDevTools/devtools-frontend/blob/main/front_end/ui/components/text_editor/config.ts#L370 @@ -16,6 +17,7 @@ export default function inlineSuggestionExt(self: { // TODO: how to refresh // status wrong const fetchSuggestion = () => { + console.log('inlineSuggestion ...'); const state = self.editor.state; const status = completionStatus(state) === 'active'; if (!status) { @@ -42,11 +44,20 @@ export default function inlineSuggestionExt(self: { return; } - // 如果不开启 show completion, 就获取不到列表 + // @NOTE: 如果不开启 show completion, 就获取不到列表 if (status) { - // TODO: 需要细化逻辑 - // return selectedCompletion(state)?.label.slice(0, lastWord.length); - return ' ' + selectedCompletion(state)?.displayLabel; + const completion = selectedCompletion(state); + if ( + completion?.label?.toString().startsWith(lastWord) || + completion?.displayLabel?.toString().startsWith(lastWord) + ) { + return ( + completion?.label.slice(lastWord.length) || + completion?.displayLabel?.slice(lastWord.length) + ); + } else { + return ' ' + (completion?.label || completion?.displayLabel); + } } return ''; }; diff --git a/src/tiddlywiki-codemirror-6/plugin.info b/src/tiddlywiki-codemirror-6/plugin.info index 8ba54a82..2de9c538 100644 --- a/src/tiddlywiki-codemirror-6/plugin.info +++ b/src/tiddlywiki-codemirror-6/plugin.info @@ -2,7 +2,7 @@ "title": "$:/plugins/oeyoews/tiddlywiki-codemirror-6", "name": "CodeMirror6", "description": "CodeMirror 6 editor", - "version": "2.4.1", + "version": "2.5.0", "core-version": ">=5.3.4", "list": "readme usage" } \ No newline at end of file