-
-
Notifications
You must be signed in to change notification settings - Fork 8
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
Place syntax around multi word links and tags #17
Conversation
const textBeforeCursor = editor.cm.state.sliceDoc(currentPosition - 1000, currentPosition); | ||
const textAfterCursor = editor.cm.state.sliceDoc(currentPosition, currentPosition + 1000); | ||
|
||
const inTag = textBeforeCursor.match(/#[\w\/\_\-]*$/) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That won't match tags that contain non-ASCII characters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you have a regex that properly matches tags with non-ASCII characters?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
slevithan/xregexp#228 (comment)
Maybe this helps? Otherwise I'd use a regex that matches everything from #
until the first \s
and test whether the part after #
is a number. If it is, discard it, otherwise keep it.
Hmm, this is indeed easier than expected. Seems like all the refactoring I did actually pays off 😅 I somewhat dislike the idea of using slicedoc, since it includes an unnecessary new method (which I am also not familiar with). Using CM and cursor positioning is probably better, it would also avoid stuff like getting 1000 characters which is indeed a bit excessive. Also, I'd rather have one function that covers all three cases, so it's easier to extend in case of adding further edge cases other people might come up with (like with the arrays in The additions to Since it is easier than expected, I'll look into writing a proper implementation later today or later this week (and of course credit you, sicne I'll take part of your code as reference). Could you make a new PR for |
There is probably a cleaner way to get the text from the current line, but because I was unfamiliar with how the cursor position and codemirror 6 worked, I went with sliceDoc. I haven't seen any performance hits yet, but 1000 chars is probably excessive. Otherwise, this seems to be working as intended, and was surprisingly easy to implement thanks to your implementation.
Currently, there is also no implementation for CM5, but I think you should just need a substitute to get the text around the cursor.
I also added some punctuation that made sense to me, but I could see people disagreeing, maybe a good place for a toggle like
Include trailing punctuation