mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-09-20 16:42:58 +00:00
fix makelist
This commit is contained in:
@@ -197,18 +197,31 @@ const makeLink = (view)=>{
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
const makeList = (type)=>(view)=>{
|
const makeList = (type) => (view) => {
|
||||||
const { from, to } = view.state.selection.main;
|
const { from, to } = view.state.selection.main;
|
||||||
|
const startLine = view.state.doc.lineAt(from);
|
||||||
|
const endLine = view.state.doc.lineAt(to);
|
||||||
const lines = [];
|
const lines = [];
|
||||||
for (let l = from; l <= to; l++) {
|
|
||||||
const lineText = view.state.doc.line(l + 1).text;
|
for (let lineNo = startLine.number; lineNo <= endLine.number; lineNo++) {
|
||||||
lines.push(lineText);
|
lines.push(view.state.doc.line(lineNo).text);
|
||||||
}
|
}
|
||||||
const joined = lines.join('\n');
|
const joined = lines.join('\n');
|
||||||
let newText;
|
|
||||||
if(type === 'UL') newText = joined.replace(/^/gm, '- ');
|
const newText = type === 'UL'
|
||||||
else newText = joined.replace(/^/gm, (m, i)=>`${i + 1}. `);
|
? joined.replace(/^/gm, '- ')
|
||||||
view.dispatch({ changes: { from, to, insert: newText } });
|
: joined.replace(/^/gm, (_, offset) => {
|
||||||
|
const lineNumber = joined.slice(0, offset).split('\n').length;
|
||||||
|
return `${lineNumber}. `;
|
||||||
|
});
|
||||||
|
|
||||||
|
view.dispatch({
|
||||||
|
changes: {
|
||||||
|
from: startLine.from,
|
||||||
|
to: endLine.to,
|
||||||
|
insert: newText
|
||||||
|
}
|
||||||
|
});
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -260,8 +273,8 @@ export const markdownKeymap = Prec.highest(keymap.of([
|
|||||||
{ key: 'Shift-Mod-m', run: makeDiv },
|
{ key: 'Shift-Mod-m', run: makeDiv },
|
||||||
{ key: 'Mod-/', run: makeComment },
|
{ key: 'Mod-/', run: makeComment },
|
||||||
{ key: 'Mod-k', run: makeLink },
|
{ key: 'Mod-k', run: makeLink },
|
||||||
{ key: 'Mod-l', run: makeList('UL') },
|
{ key: 'Mod-Shift-u', run: makeList('UL') },
|
||||||
{ key: 'Shift-Mod-l', run: makeList('OL') },
|
{ key: 'Mod-Shift-o', run: makeList('OL') },
|
||||||
{ key: 'Shift-Mod-1', run: makeHeader(1) },
|
{ key: 'Shift-Mod-1', run: makeHeader(1) },
|
||||||
{ key: 'Shift-Mod-2', run: makeHeader(2) },
|
{ key: 'Shift-Mod-2', run: makeHeader(2) },
|
||||||
{ key: 'Shift-Mod-3', run: makeHeader(3) },
|
{ key: 'Shift-Mod-3', run: makeHeader(3) },
|
||||||
|
|||||||
Reference in New Issue
Block a user