After I high light some text follow keyword search scrollbar always scroll to mid. How can I prevent this?
const highlight_effect = StateEffect.define();
const highlight_extension = StateField.define({
create() { return Decoration.none },
update(value, transaction) {
value = value.map(transaction.changes)
for (let effect of transaction.effects) {
if (effect.is(highlight_effect)) {
value = value.update({ add: effect.value, sort: true });
}
}
return value
},
provide: f => EditorView.decorations.from(f)
});
const readOnlyExtention = EditorState.readOnly.of(true);
let state = EditorState.create({doc: this.activationLogData, extensions: [basicSetup, highlight_extension, readOnlyExtention]});
let element = document.getElementById("editorCodeCustom")
this.view = new EditorView({
state,
parent: element
});
if(search){
let cursor = new SearchCursor(this.view.state.doc, search);
let count = 0;
while (cursor.next()) {
const fromPos = cursor.value.from;
const toPos = cursor.value.to;
if(count === toPos){
break;
}
count = toPos;
const highlight_decoration = Decoration.mark({
attributes: { style: "background-color: yellow" }
});
this.view.dispatch({
effects: highlight_effect.of([highlight_decoration.range(fromPos, toPos)])
});
}
}
}