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

Place syntax around multi word links and tags #17

Closed
wants to merge 6 commits into from

Conversation

Aaron-Bopp
Copy link
Contributor

@Aaron-Bopp Aaron-Bopp commented Jan 11, 2022

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

const textBeforeCursor = editor.cm.state.sliceDoc(currentPosition - 1000, currentPosition);
const textAfterCursor = editor.cm.state.sliceDoc(currentPosition, currentPosition + 1000);

const inTag = textBeforeCursor.match(/#[\w\/\_\-]*$/)
Copy link
Contributor

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.

Copy link
Owner

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?

Copy link
Contributor

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.

@chrisgrieser
Copy link
Owner

chrisgrieser commented Jan 11, 2022

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 const.ts file).


The additions to const.ts are good, but I'd leave out the trailing punctuation since this will indeed irritate a lot of people. When I add a setting menu later, I'll add trailing punctuations as a toggle there, that's a good suggestions though.


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 const.ts without the trailing punctuation? (I haven't figured out yet how merge only one commit of a PR 😅 )

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

Successfully merging this pull request may close these issues.

3 participants