Replies: 2 comments 2 replies
-
I don't have plan to implement it officially. You can create a community plugin. |
Beta Was this translation helpful? Give feedback.
0 replies
-
I have implement search and this works in Milkdown editorViewOptionsCtx editable mode = true. But how to setSelection on searchText when editable mode = false @Saul-Mirone ? function searchFromSelection(
view: EditorView,
searchText: string,
from: number,
to: number
): boolean {
const { state, dispatch } = view;
const { doc } = state;
let tr = state.tr;
let found = false;
doc.descendants((node, pos) => {
if (found || !node.isText) return;
if (pos >= from) {
const text = caseSensitive ? node.text! : node.text!.toLowerCase();
const index = text.indexOf(searchText, pos === from ? to - pos : 0);
if (index !== -1) {
const start = pos + index;
const end = start + searchText.length;
// Select the found text
tr = tr.setSelection(TextSelection.create(doc, start, end));
tr = tr.scrollIntoView();
view.dom.focus();
found = true;
}
}
});
if (found) {
dispatch(tr);
}
return found;
} |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Implement search,replace,replaceall and so on,i think it is a commonly used functions。
能不能实现搜索和替换插件,感觉这是个非常必要且高频使用的功能。代码中可以通过
···
view.dispatch(
state.tr.replace(
tr.selection.from,
tr.selection.from,
new Slice(doc.content, 0, 0)
)
···
这样来实现,我的意思是应该实现一个插件,默认提供搜索替换界面和功能。
Beta Was this translation helpful? Give feedback.
All reactions