use of org.rstudio.core.client.command.KeyboardShortcut.KeyCombination in project rstudio by rstudio.
the class ShortcutManager method handleKeyDown.
private boolean handleKeyDown(NativeEvent event) {
// generated by Qt when commands executed from menu.
if (activeEditEventType_ != EditEvent.TYPE_NONE) {
final int type = activeEditEventType_;
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
events_.fireEvent(new EditEvent(false, type));
}
});
activeEditEventType_ = EditEvent.TYPE_NONE;
keyBuffer_.clear();
return false;
}
// modal dialogs)
if (!isEnabled())
return false;
// Don't dispatch on bare modifier keypresses.
if (KeyboardHelper.isModifierKey(event.getKeyCode()))
return false;
// practice, this is better than breaking copy + paste everywhere else...
if (isEditKeyCombination(event)) {
Element target = Element.as(event.getEventTarget());
AceEditorNative editor = AceEditorNative.getEditor(target);
if (editor == null) {
keyBuffer_.clear();
return false;
}
}
// Escape key should always clear the keybuffer.
if (event.getKeyCode() == KeyCodes.KEY_ESCAPE) {
keyBuffer_.clear();
return false;
}
int keyCode = event.getKeyCode();
int modifier = KeyboardShortcut.getModifierValue(event);
// since we have code wired to that expectation
if (keyCode == 173)
keyCode = 189;
KeyCombination keyCombination = new KeyCombination(keyCode, modifier);
// is focused.
if (keyCombination.getKeyCode() == KeyCodes.KEY_F && keyCombination.getModifier() == KeyboardShortcut.CTRL) {
Element target = Element.as(event.getEventTarget());
AceEditorNative editor = AceEditorNative.getEditor(target);
if (editor != null && editor.isVimModeOn()) {
keyBuffer_.clear();
return false;
}
}
// Bail if this is an ignored key combination.
if (isIgnoredKeyCombination(keyCombination)) {
keyBuffer_.clear();
return false;
}
keyBuffer_.add(keyCombination);
// Loop through all active key maps, and attempt to find an active
// binding. 'pending' is used to indicate whether there are any bindings
// following the current state of the keybuffer.
boolean pending = false;
for (Map.Entry<KeyMapType, KeyMap> entry : keyMaps_.entrySet()) {
KeyMap map = entry.getValue();
CommandBinding binding = map.getActiveBinding(keyBuffer_);
if (binding != null) {
keyBuffer_.clear();
if (XTermWidget.isXTerm(Element.as(event.getEventTarget()))) {
if (binding.getId() == "consoleClear") {
// special case; we expect users will try to use Ctrl+L to
// clear the terminal, and don't want that to actually
// clear the currently hidden console instead
event.stopPropagation();
commands_.clearTerminalScrollbackBuffer().execute();
return false;
} else if (binding.getId() == "closeSourceDoc") {
// when focus is in the terminal and let terminal see keys
return false;
}
if (binding.getContext() != AppCommand.Context.Workbench && binding.getContext() != AppCommand.Context.Addin && binding.getContext() != AppCommand.Context.PackageDevelopment) {
// Let terminal see the keyboard input and don't execute command.
return false;
}
}
event.stopPropagation();
binding.execute();
return true;
}
if (map.isPrefix(keyBuffer_))
pending = true;
}
if (!(pending || isPrefixForEditor(keyCombination, event)))
keyBuffer_.clear();
// 'I', and some other cases)
if (!keyBuffer_.isEmpty()) {
KeyCombination keys = keyBuffer_.get(keyBuffer_.size() - 1);
if (keys.getModifier() == KeyboardShortcut.NONE)
keyBuffer_.clear();
}
return false;
}
use of org.rstudio.core.client.command.KeyboardShortcut.KeyCombination in project rstudio by rstudio.
the class ShortcutManager method swallowEvents.
private void swallowEvents(Object object) {
NativeEvent event = (NativeEvent) object;
// when seeing unhandled keys.
if (!keyBuffer_.isEmpty()) {
for (Map.Entry<KeyMapType, KeyMap> entry : keyMaps_.entrySet()) {
if (entry.getValue().isPrefix(keyBuffer_)) {
event.stopPropagation();
event.preventDefault();
return;
}
}
}
// Prevent backspace from performing a browser 'back'
if (DomUtils.preventBackspaceCausingBrowserBack(event))
return;
// Suppress save / quit events from reaching the browser
KeyCombination keys = new KeyCombination(event);
int keyCode = keys.getKeyCode();
int modifiers = keys.getModifier();
boolean isSaveQuitKey = keyCode == KeyCodes.KEY_S || keyCode == KeyCodes.KEY_W;
boolean isSaveQuitModifier = BrowseCap.isMacintosh() ? modifiers == KeyboardShortcut.META : modifiers == KeyboardShortcut.CTRL;
if (isSaveQuitKey && isSaveQuitModifier)
event.preventDefault();
// Prevent 'Ctrl+Shift+B' (toggle bookmarks)
boolean isToggleBookmarksModifier = BrowseCap.isMacintosh() ? modifiers == (KeyboardShortcut.SHIFT | KeyboardShortcut.META) : modifiers == (KeyboardShortcut.SHIFT | KeyboardShortcut.CTRL);
if (keyCode == KeyCodes.KEY_B && isToggleBookmarksModifier)
event.preventDefault();
}
use of org.rstudio.core.client.command.KeyboardShortcut.KeyCombination in project rstudio by rstudio.
the class CompletionPopupPanel method registerIgnoredKeys.
private void registerIgnoredKeys() {
resetIgnoredKeysHandle();
Set<KeyCombination> keySet = new HashSet<KeyCombination>();
keySet.add(new KeyCombination(KeyCodes.KEY_N, KeyboardShortcut.CTRL));
keySet.add(new KeyCombination(KeyCodes.KEY_P, KeyboardShortcut.CTRL));
handle_ = ShortcutManager.INSTANCE.addIgnoredKeys(keySet);
}
Aggregations