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

Add dedicated RStudio keymap #2067

Merged
merged 14 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build/gulpfile.extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const compilations = [
'positron-javascript/tsconfig.json',
'positron-notebook-controllers/tsconfig.json',
'positron-r/tsconfig.json',
'positron-rstudio-keymap/tsconfig.json',
'positron-python/tsconfig.json',
'positron-proxy/tsconfig.json',
'positron-zed/tsconfig.json',
Expand Down
1 change: 1 addition & 0 deletions build/npm/dirs.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const dirs = [
'extensions/positron-javascript',
'extensions/positron-notebook-controllers',
'extensions/positron-r',
'extensions/positron-rstudio-keymap',
'extensions/positron-python',
'extensions/positron-proxy',
'extensions/positron-zed',
Expand Down
2 changes: 2 additions & 0 deletions extensions/positron-rstudio-keymap/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

Copyright (c) 2024 Posit Software, PBC. All rights reserved.
19 changes: 19 additions & 0 deletions extensions/positron-rstudio-keymap/extension.webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*---------------------------------------------------------------------------------------------
* Copyright (C) 2024 Posit Software, PBC. All rights reserved.
*--------------------------------------------------------------------------------------------*/

//@ts-check

'use strict';

const withDefaults = require('../shared.webpack.config');

module.exports = withDefaults({
context: __dirname,
entry: {
extension: './src/extension.ts',
},
externals: {
'vscode': { commonjs: 'vscode' },
}
});
150 changes: 150 additions & 0 deletions extensions/positron-rstudio-keymap/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
{
"name": "positron-rstudio-keymap",
"displayName": "%displayName%",
"description": "%description%",
"version": "0.0.1",
"publisher": "vscode",
"license": "SEE LICENSE IN LICENSE.md",
"engines": {
"vscode": "^1.75.0"
},
"categories": [
"Keymaps"
],
"keywords": [
"keymap",
"Importer",
"Settings",
"RStudio"
],
"activationEvents": [
"onStartupFinished"
],
"main": "./out/extension.js",
"extensionKind": [
"ui",
"workspace"
],
"repository": {
"type": "git",
"url": "https://github.com/posit-dev/positron.git"
},
"scripts": {
"vscode:prepublish": "yarn run compile",
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./",
"pretest": "yarn run compile && yarn run lint",
"lint": "eslint src --ext ts"
},
"contributes": {
"configuration": {
"type": "object",
"title": "%rstudio.keymap.configuration.title%",
"properties": {
"rstudio.keymap.enable": {
"type": "boolean",
"default": false,
"description": "%rstudio.keymap.enable.description%"
}
}
},
"keybindings": [
{
"mac": "cmd+shift+n",
"win": "ctrl+shift+n",
"linux": "ctrl+shift+n",
"key": "ctrl+shift+n",
"when": "config.rstudio.keymap.enable",
"command": "r.createNewFile"
},
{
"mac": "F2",
"win": "F2",
"linux": "F2",
"key": "F2",
"when": "config.rstudio.keymap.enable && editorTextFocus",
"command": "editor.action.revealDefinition"
},
{
"mac": "cmd+option+shift+m",
"win": "ctrl+alt+shift+m",
"linux": "ctrl+alt+shift+m",
"key": "ctrl+alt+shift+m",
"when": "config.rstudio.keymap.enable && editorTextFocus",
"command": "editor.action.rename"
},
{
"mac": "cmd+shift+c",
"win": "ctrl+shift+c",
"linux": "ctrl+shift+c",
"key": "ctrl+shift+c",
"when": "config.rstudio.keymap.enable && editorTextFocus",
"command": "editor.action.commentLine"
},
{
"mac": "ctrl+1",
"win": "ctrl+1",
"linux": "ctrl+1",
"key": "ctrl+1",
"when": "config.rstudio.keymap.enable",
"command": "workbench.action.focusActiveEditorGroup"
},
{
"mac": "ctrl+2",
"win": "ctrl+2",
"linux": "ctrl+2",
"key": "ctrl+2",
"when": "config.rstudio.keymap.enable",
"command": "workbench.action.positronConsole.focusConsole"
},
{
"mac": "cmd+.",
"win": "ctrl+.",
"linux": "ctrl+.",
"key": "ctrl+.",
"when": "config.rstudio.keymap.enable",
"command": "workbench.action.showAllSymbols"
},
{
"mac": "shift+alt+k",
"win": "shift+alt+k",
"linux": "shift+alt+k",
"key": "shift+alt+k",
"when": "config.rstudio.keymap.enable",
"command": "workbench.action.openGlobalKeybindings"
},
{
"mac": "cmd+alt+i",
"win": "ctrl+alt+i.",
"linux": "ctrl+alt+i",
"key": "ctrl+alt+i",
"when": "config.rstudio.keymap.enable && editorTextFocus",
"command": "quarto.insertCodeCell"
},
{
"mac": "cmd+i",
"win": "ctrl+i",
"linux": "ctrl+i",
"key": "ctrl+i",
"when": "config.rstudio.keymap.enable && editorTextFocus",
"command": "editor.action.reindentselectedlines"
},
{
"mac": "cmd+shift+a",
"win": "ctrl+shift+a",
"linux": "ctrl+shift+a",
"key": "ctrl+shift+a",
"when": "config.rstudio.keymap.enable && editorTextFocus",
"command": "editor.action.formatSelection"
},
{
"mac": "cmd+d",
"win": "ctrl+d",
"linux": "ctrl+d",
"key": "ctrl+d",
"when": "config.rstudio.keymap.enable && editorTextFocus",
"command": "editor.action.deleteLines"
}
]
}
}
6 changes: 6 additions & 0 deletions extensions/positron-rstudio-keymap/package.nls.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"displayName": "RStudio Keymap",
"description": "RStudio keybindings for Positron",
"rstudio.keymap.configuration.title": "RStudio Keymap",
"rstudio.keymap.enable.description": "Enable RStudio key mappings for Positron",
}
8 changes: 8 additions & 0 deletions extensions/positron-rstudio-keymap/src/extension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*---------------------------------------------------------------------------------------------
* Copyright (C) 2024 Posit Software, PBC. All rights reserved.
*--------------------------------------------------------------------------------------------*/

import * as vscode from 'vscode';

export function activate(_context: vscode.ExtensionContext) {
}
16 changes: 16 additions & 0 deletions extensions/positron-rstudio-keymap/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": "../tsconfig.base.json",
"compilerOptions": {
"outDir": "./out",
"esModuleInterop": true,
"experimentalDecorators": true,
"types": [
"node"
]
},
"include": [
"src/**/*",
"../../src/vscode-dts/vscode.d.ts",
"../../src/positron-dts/positron.d.ts",
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Codicon } from 'vs/base/common/codicons';
import { ITextModel } from 'vs/editor/common/model';
import { IEditor } from 'vs/editor/common/editorCommon';
import { ILogService } from 'vs/platform/log/common/log';
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import { KeyChord, KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import { Position } from 'vs/editor/common/core/position';
import { IStatementRange } from 'vs/editor/common/languages';
import { CancellationToken } from 'vs/base/common/cancellation';
Expand All @@ -35,7 +35,8 @@ import { IPositronConsoleService } from 'vs/workbench/services/positronConsole/b
const enum PositronConsoleCommandId {
ClearConsole = 'workbench.action.positronConsole.clearConsole',
ClearInputHistory = 'workbench.action.positronConsole.clearInputHistory',
ExecuteCode = 'workbench.action.positronConsole.executeCode'
ExecuteCode = 'workbench.action.positronConsole.executeCode',
FocusConsole = 'workbench.action.positronConsole.focusConsole'
}

/**
Expand Down Expand Up @@ -106,6 +107,43 @@ export function registerPositronConsoleActions() {
}
});

/**
* Register the focus console action. This action places focus in the active console,
* if one exists.
*/
registerAction2(class extends Action2 {
/**
* Constructor.
*/
constructor() {
super({
id: PositronConsoleCommandId.FocusConsole,
title: {
value: localize('workbench.action.positronConsole.focusConsole', "Focus Console"),
original: 'Focus Console'
},
f1: true,
keybinding: {
weight: KeybindingWeight.WorkbenchContrib,
primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KeyK, KeyCode.KeyF)
},
category,
});
}

/**
* Runs action; places focus in the console's input control.
*
* @param accessor The services accessor.
*/
async run(accessor: ServicesAccessor) {
const positronConsoleService = accessor.get(IPositronConsoleService);
if (positronConsoleService.activePositronConsoleInstance) {
positronConsoleService.activePositronConsoleInstance.focusInput();
}
}
});

/**
* Register the clear input history action. This action removes everything from the active
* console language's input history.
Expand Down