app icon indicating copy to clipboard operation
app copied to clipboard

replace ->,<- and <-> by the matching arrow characters in super notes

Open IHappyDayI opened this issue 1 year ago • 0 comments

What

This PR adds an automatic replacement in the super editor when typing -> , <- or <-> by the corresponding arrow character.

Why

Personally I use a lot of → arrows in my texts to indicate a flow or an outcome of an action. The arrow characters are visually more pleasing to use, but are more difficult to type. This feature is present in the Rich Markdown Editor, which I have used almost exclusively for the last couple years in StandardNotes. This automatic replacement speeds up the typing / search for the characters to copy and paste.

Thoughts

The replacement is triggered when typing a space character, so shouldn't be a problem in case the characters are used inside of any string. The replacement only happens at the current position of typing, not in multiple places in the same line that all get matched with the regex. Without the $ in the regex the cursor would jump to the first match in the line and not replace the currently typed characters.

I used the emoji plugin from the lexical playground as a guide of how to implement this feature, because it does something very similar. However, I chose not to implement a list/map for the different arrows like the emoji plugin did, because that implementation is buggy and can lead to the application becoming unresponsive or even crashing in certain circumstances (when the regex matches strings that are not present in the map). The only stable way I've found to implement this, is by adding three separate transformers with exactly matching regex.

I've tested the changes on the Linux app and the Android app and I'm happy with the changes.

IHappyDayI avatar Jan 04 '24 12:01 IHappyDayI