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

Add cmd+i and cmd+b for Mac users #1148

Closed
Gazook89 opened this issue Dec 10, 2020 · 8 comments
Closed

Add cmd+i and cmd+b for Mac users #1148

Gazook89 opened this issue Dec 10, 2020 · 8 comments
Labels
tweak Small, non-breaking change UI/UX User Interface, user experience

Comments

@Gazook89
Copy link
Collaborator

If possible to update the editor to allow the use of common keyboard hotkeys to make formatting text faster, that would be awesome. Examples would be ctrl/cmd + i and ctrl/cmd + b to italicize and bold, respectively. And/Or something like the FancyPants editor on Reddit.

Just throwing feature requests out there to see what sticks!

@calculuschild
Copy link
Member

Currently I believe ctrl I and ctrl b already insert asterisks in the position. Is this not working for you?

Keep the suggestions coming though! It's all good!

@ericscheid
Copy link
Collaborator

The editor pane does already have keyboard shortcuts for bold and italics .. are these not working for you?

@Gazook89
Copy link
Collaborator Author

Ah, ctrl does indeed work. However, on a Mac, that isn't "right". Control works, but for most using a Mac the expectation would be that Command would do the trick instead. Perhaps if both were functional?

Also, this seems to be a one-way thing. It's not possible to un-asterisk bold or italics using the same hotkeys. It just doubles up.

@calculuschild
Copy link
Member

Ah I see. In that case, we can try to make both key combos work. That shouldn't be too hard.

There also might be a way to undo italics, but I can see that getting complicated.

For instance if you have this text and your cursor is at the X:

This sentence *has somXe italics and **bold**** inside!

What happens when you hit ctrl-i? Does the word "some" get asterisks around it? Does a new set of asterisks appear in the middle of "some"? Do the outermost asterisks disappear? Not only do you have to parse all the nearby text for italics/not italics, but you have to count numbers of asterisks to make sure you don't mess up the bold on "bold". And that problem is a nightmare. Maybe possible, but probably rough. :/

@Gazook89
Copy link
Collaborator Author

Why not just add the asterisks where the highlight/selection starts and ends? If nothing is selected, including when the cursor is just inside a word, nothing happens.

It should be relatively intuitive that the set of asterisks you need (depending on whether you choose italic or bold) appear at the start or end of a selection, even if it sort goofs up the format around other asterisks.

In your example, nothing would happen, since the cursor hasn't highlighted anything. If you highlighted the word Some, and hit ctrl I, a set of single asterisks get added to either side of Some and it no longer becomes italicized, but leaves the rest italicized.

@calculuschild
Copy link
Member

So here's where we are at now:

Why not just add the asterisks where the highlight/selection starts and ends?

So currently, ctrl-i does just that. It creates asterisks surrounding the current selected text.

Now since the original designer hadn't thought about the case where nothing is selected, ctrl-i weirdly inserted |** where | is the cursor position in that case. Ctrl-B resulted in |****. Pull Request #1078 fixed this "no selection" case so that the asterisks appear around the cursor you you can just start typing words, due to popular request. And it is a nice feature to be able to start typing in italics or bold without having to grab the mouse and drag over the words you want to modify.

I think this combination is pretty reasonable, and removing the no-select option after we so recently added it I think is going to confuse people. :/ I also like that it follows the other "snippet" behavior of inserting new code, where trying to "remove" a feature just requires extra logic.

If you highlighted the word Some, and hit ctrl I, a set of single asterisks get added to either side of Some and it no longer becomes italicized, but leaves the rest italicized.

This sounds simple in principle, but in reality it wouldn't work quite that easily. With the update to the markdown parser that will be part of v3, spacing for the asterisks becomes more strict. For example: This is **bold** works fine, but This is ** bold ** will not because spaces are not allowed directly before or after the asterisks. So then, if you want to "unbold" a selection by putting asterisks around it, you really have to know if the region is already bolded, and if not, place the asterisks like so: other words **selection** other words, but if the region is bolded, the spacing needs to go like this other words** selection **other words. If you have selected only part of a word, it gets even more convoluted. I should know, because I rewrote the italics/bold detection for Marked.js to better follow the Markdown specifications just for the Hombrewery, because people were getting all sorts of broken code to do things. Ugh...

Maybe as a future thing though. I'm not putting it completely off the table. Just not a priority for now. If you want to try your hand at a PR I'm all for it!

@calculuschild calculuschild changed the title Add common keyboard hotkeys to Editor pane. Add cmd+i and cmd+b for Mac users Dec 11, 2020
@calculuschild calculuschild added tweak Small, non-breaking change UI/UX User Interface, user experience labels Dec 11, 2020
@RKuerten
Copy link
Collaborator

I created a quick fiddle where the Ctrl+B/I shortcuts have the functionality of both adding and removing bold/italic if they are in the outmost part of the selection, but with Italics using _ instead of *. I can create a PR for it later.

You can check it here. There's also code for strikethrough biddings, but there's probably a better shortcut for it.

About Cmd key biddings, I can't help as I don't have a Mac.

@calculuschild
Copy link
Member

This has been fixed with #1191

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tweak Small, non-breaking change UI/UX User Interface, user experience
Projects
None yet
Development

No branches or pull requests

4 participants