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

deal with error and border color property . in addition allStyles config #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
19 changes: 16 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@
"ridge"
],
"default": "solid"
},
"highlightLine.allStyles":{
"type":[
"object"
],
"default":{
"highPriority": false,
"isWholeLine": true,
"borderWidth": "0 0 2px 0",
"borderStyle": "solid",
"borderColor": "red"
},
"description": "set DecorationRenderOptions json type. This property set is overwrited, if highPriority is false."
}
}
}
Expand All @@ -73,9 +86,9 @@
"test": "npm run compile && node ./node_modules/vscode/bin/test"
},
"devDependencies": {
"typescript": "^2.6.1",
"vscode": "^1.1.6",
"@types/mocha": "^2.2.42",
"@types/node": "^7.0.43",
"@types/mocha": "^2.2.42"
"typescript": "^2.6.1",
"vscode": "^1.1.11"
}
}
67 changes: 40 additions & 27 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

'use strict'
import { commands, ExtensionContext, window, workspace, Range, Position} from 'vscode'
'use strict';
import { commands, ExtensionContext, window, workspace, Range, Position } from 'vscode';
import { setTimeout } from 'timers';

export async function activate(context: ExtensionContext) {
Expand All @@ -19,10 +19,10 @@ export async function activate(context: ExtensionContext) {
*/
window.onDidChangeActiveTextEditor(() => {
try {
activeEditor = window.activeTextEditor
updateDecorations(decorationType)
activeEditor = window.activeTextEditor;
updateDecorations(decorationType);
} catch (error){
console.error("Error from ' window.onDidChangeActiveTextEditor' -->", error)
console.error("Error from ' window.onDidChangeActiveTextEditor' -->", error);
} finally {
lastActivePosition = new Position(activeEditor.selection.active.line, activeEditor.selection.active.character);
}
Expand All @@ -33,11 +33,11 @@ export async function activate(context: ExtensionContext) {
* a decoration.
*/
window.onDidChangeTextEditorSelection(() => {
activeEditor = window.activeTextEditor;
activeEditor = window.activeTextEditor;
updateDecorations(decorationType);
})
/**
*
*
* @param decorationType - defines our decorations settings.
*/
function updateDecorations(decorationType, updateAllVisibleEditors=false) {
Expand All @@ -54,23 +54,25 @@ export async function activate(context: ExtensionContext) {
//edit only currently active editor
else {
window.visibleTextEditors.forEach((editor) => {
if(editor !== window.activeTextEditor) return;
const currentPosition = editor.selection.active
const editorHasChangedLines = lastActivePosition.line !== currentPosition.line
if(editor !== window.activeTextEditor || lastActivePosition == undefined) return;

const currentPosition = editor.selection.active;
const editorHasChangedLines = lastActivePosition.line !== currentPosition.line;
const isNewEditor = activeEditor.document.lineCount === 1 && lastActivePosition.line === 0 && lastActivePosition.character == 0;
const newDecoration = { range: new Range(currentPosition, currentPosition) }
const newDecoration = { range: new Range(currentPosition, currentPosition) };

if(editorHasChangedLines || isNewEditor){
editor.setDecorations(decorationType, [newDecoration])
editor.setDecorations(decorationType, [newDecoration]);
}
});
}
}
}
catch (error){
console.error("Error from ' updateDecorations' -->", error)
console.error("Error from ' updateDecorations' -->", error);
} finally {
lastActivePosition = new Position(activeEditor.selection.active.line, activeEditor.selection.active.character);
if (activeEditor != undefined) {
lastActivePosition = new Position(activeEditor.selection.active.line, activeEditor.selection.active.character);
}
}


Expand All @@ -80,24 +82,35 @@ export async function activate(context: ExtensionContext) {
//clear all decorations
decorationType.dispose();
decorationType = getDecorationTypeFromConfig();
updateDecorations(decorationType, true)
updateDecorations(decorationType, true);
})
}



//UTILITIES
function getDecorationTypeFromConfig() {
const config = workspace.getConfiguration("highlightLine")
const borderColor = config.get("borderColor");
const borderWidth = config.get("borderWidth");
const borderStyle = config.get("borderStyle");
const decorationType = window.createTextEditorDecorationType({
const config = workspace.getConfiguration("highlightLine");
let value = {
isWholeLine: true,
borderWidth: `0 0 ${borderWidth} 0`,
borderStyle: `${borderStyle}`, //TODO: file bug, this shouldn't throw a lint error.
borderColor
})
borderWidth: `0 0 2px 0`,
borderStyle: `solid`, //TODO: file bug, this shouldn't throw a lint error.
borderColor: `red`
};
let allStyles;
allStyles = config.get("allStyles");
if (allStyles.highPriority) {
value.borderColor = config.get("borderColor");
value.borderStyle = config.get("borderStyle");
value.borderWidth = `0 0 ${config.get("borderWidth")} 0`;
value = Object.assign(value, allStyles);
} else {
value = Object.assign(allStyles, value);
value.borderColor = config.get("borderColor");
value.borderStyle = config.get("borderStyle");
value.borderWidth = `0 0 ${config.get("borderWidth")} 0`;
}
const decorationType = window.createTextEditorDecorationType(value);
return decorationType;
}

Expand Down