Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Markdown Lists - Task List, Tab behavior #5056

Open
2 tasks
JYone3A opened this issue Feb 10, 2023 · 3 comments
Open
2 tasks

Markdown Lists - Task List, Tab behavior #5056

JYone3A opened this issue Feb 10, 2023 · 3 comments

Comments

@JYone3A
Copy link

JYone3A commented Feb 10, 2023

Describe the feature

It would be nice if task lists were supported (https://github.github.com/gfm/#task-list-items-extension-), i.e. when pressing Enter while in a task list, the next line should start with * [ ] .

Another nice behavior would be if I press Tab at the beginning of an empty list item (i.e. with the caret right after * or 3. or * [ ] ), the whole line should be indented, including the list item itself. This should probably only happen if the previous line also starts with a list item definition.

Use Case

Quicker creation of task lists and sub-lists.

Proposed Solution

https://github.com/ajaxorg/ace/blob/master/src/mode/markdown.js#L33

The match regular expression could look like this:

var match = /^(\s*)(?:([-+*])|(\d+)\.)(\s+)(\[(?:x| )\]\s+)?/.exec(line);

// ...

return match[1] + marker + match[4] + (match[5] || '');

Not sure if there should always be an empty [ ] inserted, the code above would keep the checkbox state of the previous item.


No idea how to implement the Tab behavior. I don't see anything in the ace indent function that would allow customizing this from within the markdown mode?

Anyway, it should take the above regular expression into account, check if the current and the previous line start with this regexp, and if the current caret is positioned right after that. If yes, the whole line should be indented.

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

ACE version used

1.14.0

@JYone3A
Copy link
Author

JYone3A commented Mar 21, 2023

I did kind of hack the Tab indentation into ACE at runtime, by overwriting the editor.indent function. I know this is wrong (and ignores the mode, so that's no generic solution), but maybe the code helps someone who also wants this right now.

const session  = editor.getSession();
const matchMdList = /^\s*(-|\*) (\[( |x)\] )?$/;

editor.oldIndent = editor.indent;

editor.indent = function() {
    var range = this.getSelectionRange();
    
    if (range.start.row !== range.end.row || range.start.column !== range.end.column || range.start.column === 0) {
        return this.oldIndent();
    }
    
    range.start.column = 0;
    
    if (!matchMdList.test(session.getTextRange(range))) {
        return this.oldIndent();
    }
    
    var rows = this.$getSelectedRows(); // not sure if I could also use range.start.row, but this is how the original indent does it
    session.indentRows(rows.first, rows.last, "\t");
}

Copy link

This issue has not received any attention in 1 year. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@ghost
Copy link

ghost commented Mar 20, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants