Open jbailleul opened 8 months ago
@jbailleul I haven't found a good way to define it yet
@jaywcjlove If adding such an option to the commands is what's bothering you (maybe for genericity/re-usability purpose between commands), what about adding an optional parameter to the makeList()
function? I see it is only used by those three commands so could this kind of signature be ok?
const makeList = (
state: ExecuteState,
api: TextAreaTextApi,
insertBefore: string | AlterLineFunction,
selectionStrategy: 'word' | 'line' = 'word'
): void => {
// Use `selectWord()` or `selectLine()` based on the `selectionStrategy` param
...
}
With this, I would only have to override the commands from my side, and not the makeList()
function:
export const customUnorderedListCommand: ICommand = {
...unorderedListCommand,
execute: (state: ExecuteState, api: TextAreaTextApi) => {
makeList(state, api, '- ', 'line');
}
};
export const customOrderedListCommand: ICommand = {
...orderedListCommand,
execute: (state: ExecuteState, api: TextAreaTextApi) => {
makeList(state, api, (item, index) => `${index + 1}. `, 'line');
}
};
export const customCheckedListCommand: ICommand = {
...checkedListCommand,
execute: (state: ExecuteState, api: TextAreaTextApi) => {
makeList(state, api, () => `- [ ] `, 'line');
}
};
@jbailleul makeList()
method can be provided, welcome to submit PR
Hi!
I would like list commands (unordered list, ordered list and checked list commands) to be applied to the whole line instead of word. For now, I've achieved that by defining custom commands and overriding the
makeList()
function:Would it be possible to have something like a
selectionStrategy
option on the commands, that could be set toword
orline
for example? Then themakeList()
function would useselectWord()
orselectLine()
accordingly?Thanks for you great work!