Barrca 2025-02-28 20:22:44 +01:00
parent 46d6080ef3
commit fc00ca701a
2 changed files with 6 additions and 4 deletions

View file

@ -44,8 +44,8 @@ export default class InlineAIChatPlugin extends Plugin {
setSelectionInfoEffect.of({ from, to, text: selectedText })
);
} else {
// If no selection, you could clear it or do nothing
effects.push(setSelectionInfoEffect.of(null));
// If no selection, store cursor position instead of null
effects.push(setSelectionInfoEffect.of({ from, to, text: "" }));
}
// Also trigger the overlay

View file

@ -51,7 +51,8 @@ const highlightDecoration = Decoration.mark({
export const buildSelectionHiglightState = StateField.define<DecorationSet>({
create(state) {
const info = state.field(currentSelectionState);
if (info) {
if (info && info.from !== info.to) {
console.log("info", info);
return Decoration.set([highlightDecoration.range(info.from, info.to)]);
}
return Decoration.none;
@ -59,7 +60,8 @@ export const buildSelectionHiglightState = StateField.define<DecorationSet>({
update(decos, tr) {
// Check if selectionInfoField has changed
const info = tr.state.field(currentSelectionState);
if (info) {
if (info && info.from !== info.to) {
console.log("info update", info);
return Decoration.set([highlightDecoration.range(info.from, info.to)]);
}
return Decoration.none;