From 644b0b626568349dfa886654b976429d327004b9 Mon Sep 17 00:00:00 2001 From: toshikazu Date: Wed, 7 Mar 2018 11:31:09 +0900 Subject: [PATCH 1/2] deal with error and border color property . in addition allStyles config --- package.json | 19 +++++++++++--- src/extension.ts | 66 ++++++++++++++++++++++++++++-------------------- 2 files changed, 55 insertions(+), 30 deletions(-) diff --git a/package.json b/package.json index c459088..4a8a39a 100644 --- a/package.json +++ b/package.json @@ -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." } } } @@ -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" } } diff --git a/src/extension.ts b/src/extension.ts index e3778d6..e2ca08a 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -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) { @@ -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); } @@ -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) { @@ -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); + } } @@ -80,7 +82,7 @@ export async function activate(context: ExtensionContext) { //clear all decorations decorationType.dispose(); decorationType = getDecorationTypeFromConfig(); - updateDecorations(decorationType, true) + updateDecorations(decorationType, true); }) } @@ -88,16 +90,26 @@ export async function activate(context: ExtensionContext) { //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 = 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; } From f5b1a03a3fbc4d085068c5b5fd834dd2a7e4cb5c Mon Sep 17 00:00:00 2001 From: toshikazu Date: Wed, 7 Mar 2018 21:08:03 +0900 Subject: [PATCH 2/2] To pass local packaging --- src/extension.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/extension.ts b/src/extension.ts index e2ca08a..ed9378d 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -97,7 +97,8 @@ function getDecorationTypeFromConfig() { borderStyle: `solid`, //TODO: file bug, this shouldn't throw a lint error. borderColor: `red` }; - let allStyles = config.get("allStyles"); + let allStyles; + allStyles = config.get("allStyles"); if (allStyles.highPriority) { value.borderColor = config.get("borderColor"); value.borderStyle = config.get("borderStyle");