|
|
@@ -7,12 +7,11 @@ export type InsertHeader = (prefix: string) => void;
|
|
|
export const useInsertHeader = (view?: EditorView): InsertHeader => {
|
|
|
|
|
|
return useCallback((prefix) => {
|
|
|
-
|
|
|
if (view == null) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- const selection = view?.state.sliceDoc(
|
|
|
+ const selection = view.state.sliceDoc(
|
|
|
view.state.selection.main.from,
|
|
|
view.state.selection.main.to,
|
|
|
);
|
|
|
@@ -20,8 +19,8 @@ export const useInsertHeader = (view?: EditorView): InsertHeader => {
|
|
|
const cursorPos = view.state.selection.main.head;
|
|
|
const line = view.state.doc.lineAt(cursorPos);
|
|
|
const insertPos = line.text.startsWith(prefix) ? cursorPos - 1 : cursorPos;
|
|
|
- let insertText = prefix;
|
|
|
|
|
|
+ let insertText = prefix;
|
|
|
if (!line.text.startsWith(prefix)) {
|
|
|
insertText += ' ';
|
|
|
}
|