From 8ea6882589740cd764527e9a24f5053a84b91787 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Tue, 15 Dec 2015 14:50:11 +0100 Subject: [PATCH] Render missing key codes in current keyboard layout as errors in keybindings.json --- .../browser/defineKeybinding.css | 9 ++- .../browser/defineKeybinding.ts | 65 ++++++++++++++----- .../defineKeybinding/browser/status-error.svg | 1 + 3 files changed, 55 insertions(+), 20 deletions(-) create mode 100644 src/vs/editor/contrib/defineKeybinding/browser/status-error.svg diff --git a/src/vs/editor/contrib/defineKeybinding/browser/defineKeybinding.css b/src/vs/editor/contrib/defineKeybinding/browser/defineKeybinding.css index 08390cb45aa..a66ce23c3ca 100644 --- a/src/vs/editor/contrib/defineKeybinding/browser/defineKeybinding.css +++ b/src/vs/editor/contrib/defineKeybinding/browser/defineKeybinding.css @@ -51,7 +51,7 @@ background-size: 0.9em; } -/*.monaco-editor .inlineKeybindingError:before { +.monaco-editor .inlineKeybindingError:before { margin: 0.1em 0.1em 0 0.1em; content:" "; display:inline-block; @@ -59,9 +59,14 @@ width:1em; background: url(status-error.svg) 0px -0.1em no-repeat; background-size: 1em; -}*/ +} .monaco-editor .keybindingInfo { box-shadow: inset 0 0 0 1px #B9B9B9; background-color: rgba(100, 100, 250, 0.2); } + +.monaco-editor .keybindingError { + box-shadow: inset 0 0 0 1px #B9B9B9; + background-color: rgba(250, 100, 100, 0.2); +} diff --git a/src/vs/editor/contrib/defineKeybinding/browser/defineKeybinding.ts b/src/vs/editor/contrib/defineKeybinding/browser/defineKeybinding.ts index c5ae88cfa1d..02b362e632a 100644 --- a/src/vs/editor/contrib/defineKeybinding/browser/defineKeybinding.ts +++ b/src/vs/editor/contrib/defineKeybinding/browser/defineKeybinding.ts @@ -27,7 +27,8 @@ import {IHTMLContentElement} from 'vs/base/common/htmlContent'; const NLS_LAUNCH_MESSAGE = nls.localize('defineKeybinding.start', "Define Keybinding"); const NLS_DEFINE_MESSAGE = nls.localize('defineKeybinding.initial', "Press desired key combination and ENTER"); const NLS_DEFINE_ACTION_LABEL = nls.localize('DefineKeybindingAction',"Define Keybinding"); -const NLS_KB_LAYOUT_INFO_MESSAGE = nls.localize('defineKeybinding.kbLayoutMessage', "For your current keyboard layout press "); +const NLS_KB_LAYOUT_INFO_MESSAGE = nls.localize('defineKeybinding.kbLayoutInfoMessage', "For your current keyboard layout press "); +const NLS_KB_LAYOUT_ERROR_MESSAGE = nls.localize('defineKeybinding.kbLayoutErrorMessage', "You won't be able to produce this key combination under your current keyboard layout."); const INTERESTING_FILE = /keybindings\.json$/; @@ -174,28 +175,56 @@ export class DefineKeybindingController implements EditorCommon.IEditorContribut }); this._dec = this._editor.deltaDecorations(this._dec, data.map((m) : EditorCommon.IModelDeltaDecoration => { - let label = m.label; - let msg:IHTMLContentElement[] = [{ - tagName: 'span', - text: NLS_KB_LAYOUT_INFO_MESSAGE - }]; - msg = msg.concat(this._keybindingService.getHTMLLabelFor(m.keybinding)); + let isError:boolean; + let msg:IHTMLContentElement[]; + + if (!m.label) { + isError = true; + msg = [{ + tagName: 'span', + text: NLS_KB_LAYOUT_ERROR_MESSAGE + }]; + } else { + isError = false; + msg = [{ + tagName: 'span', + text: NLS_KB_LAYOUT_INFO_MESSAGE + }]; + msg = msg.concat(this._keybindingService.getHTMLLabelFor(m.keybinding)); + } return { range: m.range, - options: { - stickiness: EditorCommon.TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges, - className: 'keybindingInfo', - htmlMessage: msg, - inlineClassName: 'inlineKeybindingInfo', - overviewRuler: { - color: 'rgba(100, 100, 250, 0.6)', - darkColor: 'rgba(100, 100, 250, 0.6)', - position: EditorCommon.OverviewRulerLane.Right - } - } + options: DefineKeybindingController._decorationOptions(msg, isError) } })) } + + private static _decorationOptions(msg:IHTMLContentElement[], isError:boolean): EditorCommon.IModelDecorationOptions { + if (isError) { + return { + stickiness: EditorCommon.TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges, + className: 'keybindingError', + htmlMessage: msg, + inlineClassName: 'inlineKeybindingError', + overviewRuler: { + color: 'rgba(250, 100, 100, 0.6)', + darkColor: 'rgba(250, 100, 100, 0.6)', + position: EditorCommon.OverviewRulerLane.Right + } + } + } + return { + stickiness: EditorCommon.TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges, + className: 'keybindingInfo', + htmlMessage: msg, + inlineClassName: 'inlineKeybindingInfo', + overviewRuler: { + color: 'rgba(100, 100, 250, 0.6)', + darkColor: 'rgba(100, 100, 250, 0.6)', + position: EditorCommon.OverviewRulerLane.Right + } + } + } } class DefineKeybindingLauncherWidget implements EditorBrowser.IOverlayWidget { diff --git a/src/vs/editor/contrib/defineKeybinding/browser/status-error.svg b/src/vs/editor/contrib/defineKeybinding/browser/status-error.svg new file mode 100644 index 00000000000..a1ddb39fed6 --- /dev/null +++ b/src/vs/editor/contrib/defineKeybinding/browser/status-error.svg @@ -0,0 +1 @@ + \ No newline at end of file -- GitLab