Skip to content

Commit

Permalink
Keybindings with numbers and the shift modifier together do not work (#1
Browse files Browse the repository at this point in the history
)

* fix(normalize): convert with-shift keys when normalizing

https://forum.inkdrop.app/t/keybindings-with-numbers-and-the-shift-modifier-together-do-not-work/4482/2

* style(prettier): run

* ci(node): bump up actions

* ci(node): use 21

* fix(ci): gyp not working
  • Loading branch information
craftzdog authored Mar 13, 2024
1 parent e7bdc85 commit abd8501
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 41 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3
- uses: actions/setup-node@v3
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '18'
node-version: '20'
- if: ${{ ! startsWith(matrix.os, 'windows') }}
run: python3 -m pip install setuptools
- name: Install dependencies
run: npm i --openssl_fips=''
- name: Rebuild dependencies for Electron
Expand Down
12 changes: 6 additions & 6 deletions ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ Do you want to ask a question? Are you looking for support? The Atom message boa

### Prerequisites

* [ ] Put an X between the brackets on this line if you have done all of the following:
* Reproduced the problem in Safe Mode: http://flight-manual.atom.io/hacking-atom/sections/debugging/#using-safe-mode
* Followed all applicable steps in the debugging guide: http://flight-manual.atom.io/hacking-atom/sections/debugging/
* Checked the FAQs on the message board for common solutions: https://discuss.atom.io/c/faq
* Checked that your issue isn't already filed: https://github.com/issues?utf8=✓&q=is%3Aissue+user%3Aatom
* Checked that there is not already an Atom package that provides the described functionality: https://atom.io/packages
- [ ] Put an X between the brackets on this line if you have done all of the following:
- Reproduced the problem in Safe Mode: http://flight-manual.atom.io/hacking-atom/sections/debugging/#using-safe-mode
- Followed all applicable steps in the debugging guide: http://flight-manual.atom.io/hacking-atom/sections/debugging/
- Checked the FAQs on the message board for common solutions: https://discuss.atom.io/c/faq
- Checked that your issue isn't already filed: https://github.com/issues?utf8=✓&q=is%3Aissue+user%3Aatom
- Checked that there is not already an Atom package that provides the described functionality: https://atom.io/packages

### Description

Expand Down
4 changes: 2 additions & 2 deletions PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
### Requirements

* Filling out the template is required. Any pull request that does not include enough information to be reviewed in a timely manner may be closed at the maintainers' discretion.
* All new code requires tests to ensure against regressions
- Filling out the template is required. Any pull request that does not include enough information to be reviewed in a timely manner may be closed at the maintainers' discretion.
- All new code requires tests to ensure against regressions

### Description of the Change

Expand Down
20 changes: 10 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
"electron-mocha": "^12.0.0",
"electron-rebuild": "^3.2.9",
"eslint": "^8.41.0",
"eslint-config-prettier": "^8.8.0",
"eslint-config-prettier": "^9.1.0",
"lolex": "1.4.0",
"prettier": "^2.8.8",
"prettier": "^3.2.5",
"rimraf": "2.2.2",
"sinon": "1.17.3",
"space-pencil": "0.3.0",
Expand Down
3 changes: 2 additions & 1 deletion spec/helpers-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ describe('.normalizeKeystrokes(keystrokes)', () =>
assert.equal(normalizeKeystrokes('ctrl-x'), 'ctrl-x')
assert.equal(normalizeKeystrokes('a'), 'a')
assert.equal(normalizeKeystrokes('shift-a'), 'shift-A')
assert.equal(normalizeKeystrokes('shift-9'), 'shift-9')
assert.equal(normalizeKeystrokes('shift-9'), '(')
assert.equal(normalizeKeystrokes('shift'), 'shift')
assert.equal(normalizeKeystrokes('-'), '-')
assert.equal(normalizeKeystrokes('- -'), '- -')
assert.equal(normalizeKeystrokes('a b'), 'a b')
Expand Down
10 changes: 8 additions & 2 deletions spec/keymap-manager-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2184,7 +2184,10 @@ describe('KeymapManager', function () {
'ctrl-a': 'x'
`
)
keymapManager.loadKeymap(keymapFilePath, { watch: true, watchImmediately: true })
keymapManager.loadKeymap(keymapFilePath, {
watch: true,
watchImmediately: true
})
subscription = keymapManager.watchSubscriptions[keymapFilePath]
return assert.equal(
keymapManager.findKeyBindings({ command: 'x' }).length,
Expand Down Expand Up @@ -2325,7 +2328,10 @@ describe('KeymapManager', function () {
assert(!reloaded)

// Can start watching again after cancelling
keymapManager.loadKeymap(keymapFilePath, { watch: true, watchImmediately: true })
keymapManager.loadKeymap(keymapFilePath, {
watch: true,
watchImmediately: true
})
fs.writeFileSync(
keymapFilePath,
`\
Expand Down
17 changes: 14 additions & 3 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,20 @@ var normalizeKeystroke = function (keystroke) {
} else {
if (isUpperCaseCharacter(primaryKey)) {
modifiers.add('shift')
}
if (modifiers.has('shift') && isLowerCaseCharacter(primaryKey)) {
primaryKey = primaryKey.toUpperCase()
} else if (modifiers.has('shift')) {
if (isLowerCaseCharacter(primaryKey)) {
primaryKey = primaryKey.toUpperCase()
} else if (isLatinCharacter(primaryKey)) {
const characters = KeyboardLayout.getCurrentKeymap()
const code = Object.keys(characters).find(
code => characters[code].unmodified === primaryKey
)
const keyWithShift = characters[code]?.withShift
if (keyWithShift) {
primaryKey = keyWithShift
modifiers.delete('shift')
}
}
}
}

Expand Down
24 changes: 12 additions & 12 deletions src/keymap-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -967,19 +967,19 @@ module.exports = KeymapManager = (function () {
target != null &&
target !== document
) {
partialMatchCandidates = partialMatchCandidates.filter(function (
binding
) {
if (
!ignoreKeystrokes.has(binding.keystrokes) &&
target.webkitMatchesSelector(binding.selector)
) {
partialMatches.push(binding)
return false
} else {
return true
partialMatchCandidates = partialMatchCandidates.filter(
function (binding) {
if (
!ignoreKeystrokes.has(binding.keystrokes) &&
target.webkitMatchesSelector(binding.selector)
) {
partialMatches.push(binding)
return false
} else {
return true
}
}
})
)
target = target.parentElement
}
return partialMatches.sort((a, b) => b.keystrokeCount - a.keystrokeCount)
Expand Down

0 comments on commit abd8501

Please sign in to comment.