microsoft / TypeScript-Sublime-Plugin

IO wrapper around TypeScript language services, allowing for easy consumption by editor plugins
Apache License 2.0
1.72k stars 237 forks source link

Plugin blocks Alt+, #736

Open dhnm opened 4 years ago

dhnm commented 4 years ago

When Alt+, is pressed, typescript_signature_popup command is called, preventing me from typing < symbol on QWERTZ keyboard.

benwiley4000 commented 4 years ago

I have the same issue. @rouxfeur did you find a workaround? This prevents me from using this plugin with Sublime.

benwiley4000 commented 4 years ago

This problem is not just for QWERTZ, it also exists for QWERTY Canadian Multilingual layout (English+French), which is used for any "Canadian French language" Mac keyboard.

benwiley4000 commented 4 years ago

I do have a workaround which is to comment out that shortcut from the keyboard shortcuts file in the package source directory.

  1. Open the file (on macOS it's at ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/TypeScript/Default.sublime-keymap)
  2. Go to line 130 and comment out the rule for "alt+,":

    },    // In case when auto match is enabled, only format if not within {}
    // {
    //     "keys": [ "alt+,"],
    //     "command": "typescript_signature_popup",
    //     "context": [
    //         { "key": "selector", "operator": "equal", "operand": "source.ts, source.tsx, source.js, source.jsx" },
    //         { "key": "tooltip_supported", "operator": "equal", "operand": true}
    
    //     ]
    // },
    {
  3. Save and restart Sublime.
SlovakianCanon commented 4 years ago

Spent so much time trying to figure this out, it should really be addressed. The workaround by @benwiley4000 does work until then.

benwiley4000 commented 4 years ago

@SlovakianCanon yep, it came back for me today because my workaround gets overwritten every time the plugin updates.

bevacqua commented 3 years ago

Wrote this script to fix this automatically from my zshfiles because this issue is the worst. It overwrites the keymap file, stripping the alt+, shortcut

const fs = require('fs')

tryOrExit(main)

function main() {
  const [keymapFile] = process.argv.slice(2)

  const keymapJson = readFileOrExit(keymapFile)

  // strip comments 🤷‍♂️
  const keymapStripped = keymapJson.replace(/\/\/.*/mg, '')

  const keymap = parseJsonOrExit(keymapStripped)

  const nextKeymap = getNextKeymap(keymap)
  const nextKeymapJson = JSON.stringify(nextKeymap, null, 2)

  writeFileOrExit(keymapFile, nextKeymapJson + '\n')
}

function readFileOrExit(file) {
  return tryOrExit(() => fs.readFileSync(file, 'utf8'))
}

function writeFileOrExit(file, contents) {
  return tryOrExit(() => fs.writeFileSync(file, contents, 'utf8'))
}

function parseJsonOrExit(json) {
  return tryOrExit(() => JSON.parse(json))
}

function getNextKeymap(keymap) {
  return keymap.filter(definition => (
    !Array.isArray(definition.keys) ||
    definition.keys.length !== 1 ||
    definition.keys[0] !== 'alt+,'
  ))
}

function tryOrExit(fn) {
  try {
    return fn()
  } catch (_err) {
    // rule of silence
    process.exit(0)
  }
}

Usage:

node hacks/autofix-sublime-typescript-plugin ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/TypeScript/Default.sublime-keymap

Example: https://github.com/bevacqua/dotfiles/commit/585dfddba7478738a20d9df64b35e2e7d67e4f36