Skip to content
Open
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
out
node_modules


.DS_Store
19 changes: 14 additions & 5 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
// A launch configuration that compiles the extension and then opens it inside a new window
{
"version": "0.1.0",
"version": "0.2.0",
"configurations": [
{
"name": "Launch Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}"],
"args": [
"--extensionDevelopmentPath=${workspaceRoot}"
],
"stopOnEntry": false,
"sourceMaps": true,
"outDir": "${workspaceRoot}/out/src",
"outFiles": [
"${workspaceRoot}/out/**/*.js"
],
"preLaunchTask": "npm"
},
{
"name": "Launch Tests",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}", "--extensionTestsPath=${workspaceRoot}/out/test"],
"args": [
"--extensionDevelopmentPath=${workspaceRoot}",
"--extensionTestsPath=${workspaceRoot}/out/test"
],
"stopOnEntry": false,
"sourceMaps": true,
"outDir": "${workspaceRoot}/out/test",
"outFiles": [
"${workspaceRoot}/out/**/*.js"
],
"preLaunchTask": "npm"
}
]
Expand Down
18 changes: 8 additions & 10 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,24 @@
// ${fileDirname}: the current opened file's dirname
// ${fileExtname}: the current opened file's extension
// ${cwd}: the current working directory of the spawned process

// A task runner that calls a custom npm script that compiles the extension.
{
"version": "0.1.0",

"version": "2.0.0",
// we want to run npm
"command": "npm",

// the command is a shell script
"isShellCommand": true,

// show the output window only if unrecognized errors occur.
"showOutput": "silent",

// we run the custom script "compile" as defined in package.json
"args": ["run", "compile", "--loglevel", "silent"],

"args": [
"run",
"compile",
"--loglevel",
"silent"
],
// The tsc compiler is started in watching mode
"isWatching": true,

"isBackground": true,
// use the standard tsc in watch mode problem matcher to find compile problems in the output.
"problemMatcher": "$tsc-watch"
}
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ Jumpy settings can be configured by adding entries into your `settings.json` (Fi

`"jumpy.lightThemeForeground"`: Text color of Jumpy decoration in light themes

`"jumpy.codeCreatingMode"`: Mode of creating code lenght

* Fixed: Always the same length. And you can set code length.
* Variable: According to the target number, code length is variable.

`"jumpy.codeChars"`: Characters used to generate code

`"jumpy.fixedCodeLength"`: [Fixed mode only] Fixed code length, need to greater than 1

## Support

[Create an issue](https://github.com/wmaurer/vscode-jumpy/issues)
19 changes: 19 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,25 @@
"type": "string",
"default": "white",
"description": "Text color of Jumpy decoration in light themes"
},
"jumpy.codeCreatingMode": {
"type": "string",
"default": "Fixed",
"description": "Mode of creating code length (Fixed or Variable)",
"enum": [
"Fixed",
"Variable"
]
},
"jumpy.codeChars": {
"type": "string",
"default": "abcdefghijklmnopqrstuvwxyz",
"description": "Characters used to generate code"
},
"jumpy.fixedCodeLength": {
"type": "number",
"default": 2,
"description": "[Fixed mode only] Fixed code length, need to greater than 1"
}
}
}
Expand Down
204 changes: 123 additions & 81 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,87 @@ import * as vscode from 'vscode';

import {
Decoration,
createCodeArray,
createCharArray,
createFixedCodeArray,
createVariableCodeArray,
createDataUriCaches,
getCodeIndex,
getCodeIndices,
getLines,
createTextEditorDecorationType,
createDecorationOptions,
} from './jumpy-vscode';
import { JumpyPosition, JumpyFn, jumpyWord, jumpyLine } from './jumpy-positions';

export function activate(context: vscode.ExtensionContext) {
const codeArray = createCodeArray();

// decorations, based on configuration
const editorConfig = vscode.workspace.getConfiguration('editor');
const configuration = vscode.workspace.getConfiguration('jumpy');
enum CodeType {
Fixed,
Variable
};

let fontFamily = configuration.get<string>('fontFamily');
fontFamily = fontFamily || editorConfig.get<string>('fontFamily');
// configrations
let fontFamily: string = "";
let fontSize: number = 1;
let darkDecoration: Decoration = null;
let lightDecoration: Decoration = null;

let fontSize = configuration.get<number>('fontSize');
fontSize = fontSize || editorConfig.get<number>('fontSize') - 1;
let codeType: CodeType = CodeType.Fixed;
let codeChars: string = "";
let fixedCodeLength: number = 1;

const colors = {
darkBgColor: configuration.get<string>('darkThemeBackground'),
darkFgColor: configuration.get<string>('darkThemeForeground'),
lightBgColor: configuration.get<string>('lightThemeBackground'),
lightFgColor: configuration.get<string>('lightThemeForeground'),
};
loadConfiguration();

const darkDecoration = {
bgColor: colors.darkBgColor,
fgColor: colors.darkFgColor,
fontFamily: fontFamily,
fontSize: fontSize,
};
const lightDecoration = {
bgColor: colors.lightBgColor,
fgColor: colors.lightFgColor,
fontFamily: fontFamily,
fontSize: fontSize,
};
// property
let positions: JumpyPosition[] = [];
let isJumpyMode: boolean = false;
let keysOfCode: string[] = [];

createDataUriCaches(codeArray, darkDecoration, lightDecoration);
let charArray: string[] = [];
let codeArray: string[] = [];
const decorationType = createTextEditorDecorationType();

const decorationTypeOffset2 = createTextEditorDecorationType(darkDecoration);
const decorationTypeOffset1 = createTextEditorDecorationType(darkDecoration);
charArray = createCharArray(codeChars);
if (codeType == CodeType.Fixed) {
codeArray = createFixedCodeArray(charArray, fixedCodeLength);
createDataUriCaches(codeArray, darkDecoration, lightDecoration);
}

let positions: JumpyPosition[] = null;
let firstLineNumber = 0;
let isJumpyMode: boolean = false;
setJumpyMode(false);
let firstKeyOfCode: string = null;

console.log(fontFamily)

function loadConfiguration() {
const editorConfig = vscode.workspace.getConfiguration('editor');
const configuration = vscode.workspace.getConfiguration('jumpy');

fontFamily = configuration.get<string>('fontFamily');
fontFamily = fontFamily || editorConfig.get<string>('fontFamily');
fontSize = configuration.get<number>('fontSize');
fontSize = fontSize || editorConfig.get<number>('fontSize') - 1;

const colors = {
darkBgColor: configuration.get<string>('darkThemeBackground'),
darkFgColor: configuration.get<string>('darkThemeForeground'),
lightBgColor: configuration.get<string>('lightThemeBackground'),
lightFgColor: configuration.get<string>('lightThemeForeground'),
};

darkDecoration = {
bgColor: colors.darkBgColor,
fgColor: colors.darkFgColor,
fontFamily: fontFamily,
fontSize: fontSize,
};
lightDecoration = {
bgColor: colors.lightBgColor,
fgColor: colors.lightFgColor,
fontFamily: fontFamily,
fontSize: fontSize,
};

codeType = CodeType[configuration.get<string>('codeCreatingMode')];
codeChars = configuration.get<string>('codeChars');
fixedCodeLength = Math.max(configuration.get<number>('fixedCodeLength'), 1);
}

function setJumpyMode(value: boolean) {
isJumpyMode = value;
Expand All @@ -65,50 +94,35 @@ export function activate(context: vscode.ExtensionContext) {
const editor = vscode.window.activeTextEditor;

const getLinesResult = getLines(editor);
positions = jumpyFn(codeArray.length, getLinesResult.firstLineNumber, getLinesResult.lines, regexp);

const decorationsOffset2 = positions
.map(
(position, i) =>
position.charOffset == 1
? null
: createDecorationOptions(
position.line,
position.character,
position.character + 2,
context,
codeArray[i],
),
)
.filter(x => !!x);

const decorationsOffset1 = positions
.map(
(position, i) =>
position.charOffset == 2
? null
: createDecorationOptions(
position.line,
position.character,
position.character + 2,
context,
codeArray[i],
),
)
.filter(x => !!x);

editor.setDecorations(decorationTypeOffset2, decorationsOffset2);
editor.setDecorations(decorationTypeOffset1, decorationsOffset1);
const maxDecorations = (codeType == CodeType.Fixed) ? codeArray.length : -1;
positions = jumpyFn(maxDecorations, getLinesResult.firstLineNumber, getLinesResult.lines, regexp);

if (codeType == CodeType.Variable) {
codeArray = createVariableCodeArray(charArray, positions.length);
createDataUriCaches(codeArray, darkDecoration, lightDecoration);
}

const decorations = positions
.map((position, i) =>
createDecorationOptions(
position.line,
position.character,
codeArray[i]
)
);
console.log(decorations)

editor.setDecorations(decorationType, decorations);

setJumpyMode(true);
firstKeyOfCode = null;
keysOfCode = [];
}

function exitJumpyMode() {
const editor = vscode.window.activeTextEditor;
setJumpyMode(false);
editor.setDecorations(decorationTypeOffset2, []);
editor.setDecorations(decorationTypeOffset1, []);

editor.setDecorations(decorationType, []);
}

const jumpyWordDisposable = vscode.commands.registerCommand('extension.jumpy-word', () => {
Expand Down Expand Up @@ -136,22 +150,39 @@ export function activate(context: vscode.ExtensionContext) {
const editor = vscode.window.activeTextEditor;
const text: string = args.text;

if (text.search(/[a-z]/i) === -1) {
let regexp = new RegExp('[' + charArray.join("") + ']', 'i');
if (text.search(regexp) === -1) {
exitJumpyMode();
return;
}

if (!firstKeyOfCode) {
firstKeyOfCode = text;
keysOfCode.push(text);
const indices: number[] = getCodeIndices(positions.length, codeArray, keysOfCode.join("").toLowerCase());

// invalid char
if (indices.length == 0) {
exitJumpyMode();
return;
}

const code = firstKeyOfCode + text;
const position = positions[getCodeIndex(code.toLowerCase())];
// not unique
if (indices.length != 1) {
const decorations = indices
.map((index, i) =>
createDecorationOptions(
positions[index].line,
positions[index].character,
codeArray[index]
)
)

editor.setDecorations(decorationType, decorations);
return;
}

editor.setDecorations(decorationTypeOffset2, []);
editor.setDecorations(decorationTypeOffset1, []);
editor.setDecorations(decorationType, []);

const position = positions[indices[0]];
vscode.window.activeTextEditor.selection = new vscode.Selection(
position.line,
position.character,
Expand All @@ -173,6 +204,17 @@ export function activate(context: vscode.ExtensionContext) {

const didChangeActiveTextEditorDisposable = vscode.window.onDidChangeActiveTextEditor(event => exitJumpyMode());
context.subscriptions.push(didChangeActiveTextEditorDisposable);

const didChangeConfigurationDisposable = vscode.workspace.onDidChangeConfiguration(event => {
loadConfiguration();

charArray = createCharArray(codeChars);
if (codeType == CodeType.Fixed) {
codeArray = createFixedCodeArray(charArray, fixedCodeLength);
createDataUriCaches(codeArray, darkDecoration, lightDecoration);
}
});
context.subscriptions.push(didChangeConfigurationDisposable);
}

export function deactivate() {}
export function deactivate() { }
Loading