last fixes

This commit is contained in:
Víctor Losada Hernández
2026-09-27 22:50:42 +02:00
parent a39b86edf0
commit 3ec85b6f52
@@ -62,7 +62,6 @@ const forEachSelection = (view, fn) => {
return true; return true;
}; };
const insertTab = (view)=>{ const insertTab = (view)=>{
// If any selection spans multiple lines, delegates to CodeMirror's indentMore // If any selection spans multiple lines, delegates to CodeMirror's indentMore
// Otherwise inserts two spaces at each cursor/selection // Otherwise inserts two spaces at each cursor/selection
@@ -301,38 +300,35 @@ const makeList = (type)=>(view)=>{
return true; return true;
}; };
const makeHeader = (level)=>(view)=>{ const makeHeader = (level)=>(view)=>forEachSelection(view, (state, range)=>{
const { from, to } = view.state.selection.main; const { from, to } = range;
const selected = view.state.doc.sliceString(from, to); const selected = state.doc.sliceString(from, to);
const text = `${'#'.repeat(level)} ${selected}`; const insert = `${'#'.repeat(level)} ${selected}`;
if(selected.length === 0) { if(selected.length === 0) {
view.dispatch({ changes: { from, to, insert: text }, selection: { anchor: from + text.length } }); return { changes: { from, to, insert: insert }, range: EditorSelection.cursor(from + insert.length) };
} else { } else {
view.dispatch({ changes: { from, to, insert: text } }); return { changes: { from, to, insert: insert }, range};
} }
});
return true; const newColumn = (view)=>forEachSelection(view, (state, range)=>{
}; const { from, to } = range;
const newColumn = (view)=>{
const { from, to } = view.state.selection.main;
const insert = '\n\\column\n\n' ; const insert = '\n\\column\n\n' ;
view.dispatch({ return {
changes : { from, to, insert }, changes : { from, to, insert },
selection : { anchor: from + insert.length } range: EditorSelection.cursor(from + insert.length)
});
return true;
}; };
});
const newPage = (view)=>{ const newPage = (view)=>forEachSelection(view, (state, range)=>{
const { from, to } = view.state.selection.main; const { from, to } = range;
const insert = '\n\\page\n\n'; const insert = '\n\\page\n\n';
view.dispatch({
return {
changes: { from, to, insert }, changes: { from, to, insert },
selection : { anchor: from + insert.length } range: EditorSelection.cursor(from + insert.length)
});
return true;
}; };
});
export const generalKeymap = Prec.high(keymap.of([ export const generalKeymap = Prec.high(keymap.of([
{ key: 'Tab', run: insertTab }, //runs indentMore if multiple lines selected in a single selection { key: 'Tab', run: insertTab }, //runs indentMore if multiple lines selected in a single selection