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

New keyboard shortcuts + tooltips refactoring #519

Merged
merged 24 commits into from
Jan 22, 2018

Conversation

Akryum
Copy link
Member

@Akryum Akryum commented Jan 15, 2018

  • New keyboard shortcuts
  • Teaks for shortcuts in tooltips
  • New $t translation plugin
  • Tooltips with shortcuts are now declared in a locale file (easier to manage)
  • Improved entry lists keyboard navigation (scrolling)

We may want to move all texts to the locale file. Also, this open up translation for a future PR.

@Akryum Akryum self-assigned this Jan 15, 2018
@Akryum Akryum added this to the v4.1.0 milestone Jan 15, 2018
@Akryum Akryum added this to In Progress in v4.x Jan 15, 2018
@Akryum Akryum moved this from In Progress to Review in v4.x Jan 16, 2018
@@ -0,0 +1,17 @@
import Vue from 'vue'

// Env
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now since you moved this code to a separate file this comment seems redundant

},
EventsHistory: {
filter: {
tooltip: '[F] To filter on components, type <span class="input-example"><i class="material-icons">search</i> &lt;MyComponent&gt;</span> or just <span class="input-example"><i class="material-icons">search</i> &lt;mycomp</span>.'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HTML with classes in translations make it much harder to maintain code dependent on it, you never know which change might affect it. I'd be careful about this

@@ -24,6 +24,8 @@ const mutations = {
state.inspectedIndex = -1
},
'INSPECT' (state, index) {
if (index < 0) index = 0
if (index >= state.events.length) index = state.events.length - 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't this be enough actually?

state.inspectedIndex = Math.max(0, state.events.length - 1)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No? 🙃

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, true. It would have to be:

Math.min(Math.max(0, index), state.events.length - 1)

but it wouldn't be necessarily more readable ;D

keys
},
replacer: text => {
text = text.replace(keyboardReg, '<span class="keyboard">$1</span>')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this solution. Now whenever [] or || appears somewhere in translation, it's going to wrap this part with one of those elements. As for the icon - if it's a generic app-wide solution I'm ok with it, but probably with better interpolation signs. e.g <<iconName>>, or at least ||iconName|| - though the first one more readable I guess.
But keyboard is rather case specific thing, and I wouldn't put it here. I'm thinking about alternative ways, and perhaps it would be better to make a dedicated file just for tooltips content, and import keys explicitly there.
That would leave us with translations in tact, without extra concerns. WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are going to have a lot of keyboard shortcuts in the strings--more than icons 😛

@Akryum
Copy link
Member Author

Akryum commented Jan 20, 2018

Here is a summary of the keyboard shortcuts: https://docs.google.com/spreadsheets/d/1iv3cBE1BpW8mRZLZQDWDbXMmncscmplZ6tJaYocue48/edit?usp=sharing
(when no input or textarea has focus)

For example, modifier 'ctrl+alt' isn't dispatch if 'shift' is pressed too.
@Akryum
Copy link
Member Author

Akryum commented Jan 20, 2018

The order of modifiers is:

  1. ctrl (also works with Mac meta key)
  2. shift
  3. alt

They are joined together with a +

Examples of valid modifiers:

'' // No modifier
'ctrl'
'ctrl+shift'
'ctrl+alt'
'ctrl+shift+alt'

Examples of invalid modifiers:

null
'ctrl-alt'
'shift+ctrl'
'alt+shift+ctrl'

Copy link
Member

@posva posva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like Alt+C and Alt+E do not work on Mac, they must be reserved or something.
BTW, you may want to use https://github.com/shentao/vue-global-events for handling global events 😄

@Akryum
Copy link
Member Author

Akryum commented Jan 21, 2018

@posva Changed to Ctrl|Meta + 1..3

@Akryum Akryum mentioned this pull request Jan 21, 2018
Copy link
Member

@michalsnik michalsnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last comment from me, other than that it looks really good. Great job @Akryum :)

inspectedIndex (value) {
this.$nextTick(() => {
const el = value === -1 ? this.$refs.baseEntry : this.$refs.entries[value]
el && scrollIntoView(document.querySelector('.left .scroll'), el, false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend we use .js- prefixed classes for everything that is being handled by JS. It would allow us to more safely deal with the code and potential refactors.

@posva
Copy link
Member

posva commented Jan 21, 2018

Ha, realized later that Cmd+numbers may not be that good because cmd+shift+3 does a screenshot in Mac so if your number is on shift, you can use it. I tested on programmer dvorak and none work. Maybe we could use alt+{ and alt+} to change tabs, a bit like cmd+{/ctrl+{ (that I think do not work on azerty keyboard because you have to use shift as well 😆 )

On another topic, I think the keydown isn't the most explicit solution to bind to shortcuts, it's not because I created it 😆 but I think https://github.com/shentao/vue-global-events could be helpful. I added a feature (still on PR) to filter events (could be used to not trigger events on inputs and textareas as you did)

@Akryum
Copy link
Member Author

Akryum commented Jan 22, 2018

Ha, realized later that Cmd+numbers may not be that good because cmd+shift+3 does a screenshot in Mac so if your number is on shift, you can use it. I tested on programmer dvorak and none work.

Tested on MacBook and working even with Dvorak layout. Just don't press Shift key 😛

@Akryum Akryum merged commit 000a632 into vuejs:master Jan 22, 2018
v4.x automation moved this from Review to Done Jan 22, 2018
@Akryum Akryum deleted the keyboard-shortcuts branch January 22, 2018 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
v4.x
Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants