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;
};
const insertTab = (view)=>{
// If any selection spans multiple lines, delegates to CodeMirror's indentMore
// Otherwise inserts two spaces at each cursor/selection
@@ -301,38 +300,35 @@ const makeList = (type)=>(view)=>{
return true;
};
const makeHeader = (level)=>(view)=>{
const { from, to } = view.state.selection.main;
const selected = view.state.doc.sliceString(from, to);
const text = `${'#'.repeat(level)} ${selected}`;
const makeHeader = (level)=>(view)=>forEachSelection(view, (state, range)=>{
const { from, to } = range;
const selected = state.doc.sliceString(from, to);
const insert = `${'#'.repeat(level)} ${selected}`;
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 {
view.dispatch({ changes: { from, to, insert: text } });
return { changes: { from, to, insert: insert }, range};
}
});
return true;
};
const newColumn = (view)=>{
const { from, to } = view.state.selection.main;
const newColumn = (view)=>forEachSelection(view, (state, range)=>{
const { from, to } = range;
const insert = '\n\\column\n\n' ;
view.dispatch({
return {
changes : { from, to, insert },
selection : { anchor: from + insert.length }
});
return true;
range: EditorSelection.cursor(from + insert.length)
};
});
const newPage = (view)=>{
const { from, to } = view.state.selection.main;
const newPage = (view)=>forEachSelection(view, (state, range)=>{
const { from, to } = range;
const insert = '\n\\page\n\n';
view.dispatch({
return {
changes: { from, to, insert },
selection : { anchor: from + insert.length }
});
return true;
range: EditorSelection.cursor(from + insert.length)
};
});
export const generalKeymap = Prec.high(keymap.of([
{ key: 'Tab', run: insertTab }, //runs indentMore if multiple lines selected in a single selection