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

updates #44

Closed
wants to merge 9 commits into from
Closed
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@
/coverage
*.log
__*
.history
*.vsix
.DS_Store
yarn.*
1 change: 1 addition & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ out/**/*.map
src/**/*
tsconfig.json
yarn-error.log
.history
16 changes: 11 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,6 @@
"darkseagreen"
]
},
"textmarker.defaultHighlightColor": {
"description": "Color to be used once all colors listed in `textmarker.highlightColors` are used",
"type": "string",
"default": "gray"
},
"textmarker.defaultHighlightOpacity": {
"description": "Opacity to be used when one is not given in the highlight color",
"type": "number",
Expand Down Expand Up @@ -199,6 +194,11 @@
"description": "Allow usage data to be collected",
"type": "boolean",
"default": true
},
"textmarker.enableAutoHighlight": {
"description": "enable selection auto highlight",
"type": "boolean",
"default": true
}
}
},
Expand Down Expand Up @@ -238,6 +238,11 @@
"title": "Toggle Mode for Whole/Partial Match",
"category": "TextMarker"
},
{
"command": "textmarker.toggleAutoHighlight",
"title": "Toggle Selection Auto Highlight",
"category": "TextMarker"
},
{
"command": "textmarker.clearAllHighlight",
"title": "Clear All Highlights",
Expand Down Expand Up @@ -348,6 +353,7 @@
"dependencies": {
"color-name": "1.1.4",
"color-rgba": "2.1.1",
"lodash.debounce": "^4.0.8",
"fp-ts": "2.3.1",
"lodash.isnumber": "3.0.3",
"uuid": "3.3.3",
Expand Down
55 changes: 55 additions & 0 deletions src/auto-hl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import * as vscode from 'vscode'
const debounce = require('lodash.debounce')

export function initAutoHighlight(context: vscode.ExtensionContext) {
// command
const AutoHLCommand = 'textmarker.toggleAutoHighlight'
context.subscriptions.push(vscode.commands.registerCommand(AutoHLCommand, () => {
vscode.workspace.getConfiguration().update('textmarker.enableAutoHighlight', !getCurrentHLConfig(), true)
}))

// statusbar
let AutoHLStatusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 100)
AutoHLStatusBar.command = AutoHLCommand
context.subscriptions.push(AutoHLStatusBar)
updateStatusBarItem(AutoHLStatusBar, getCurrentHLConfig())

// selection
vscode.window.onDidChangeTextEditorSelection(
debounce(function (e: vscode.TextEditorSelectionChangeEvent) {
let editor = vscode.window.activeTextEditor

if (
getCurrentHLConfig() && // hl is on
(editor && !editor.selection.isEmpty) && // something is selected
(e && e.kind == 2) // selected by mouse
) {
vscode.commands.executeCommand('textmarker.toggleHighlight')
}
}, 300)
)

// update on config change
vscode.workspace.onDidChangeConfiguration((e: any) => {
if (e.affectsConfiguration('textmarker')) {
updateStatusBarItem(AutoHLStatusBar, getCurrentHLConfig())
}
})
}

function getCurrentHLConfig() {
return vscode.workspace.getConfiguration('textmarker').enableAutoHighlight
}

function updateStatusBarItem(item: vscode.StatusBarItem, type: any) {
if (type) {
item.text = '$(symbol-keyword)'
item.tooltip = 'TextMarker Toggle: Auto Highlight Enabled'
}
else {
item.text = '$(symbol-color)'
item.tooltip = 'TextMarker Toggle: Auto Highlight Disabled'
}

item.show()
}
3 changes: 3 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {getVsTelemetryReporterCreator} from './lib/telemetry/vscode-telemetry-re
import {join} from 'path';
import WorkspaceAdaptor from './lib/vscode/workspace';
import {TelemetryReporterLocator} from './lib/telemetry/telemetry-reporter-locator';
import {initAutoHighlight} from './auto-hl'

const workspace = new WorkspaceAdaptor(vscode.workspace);
const reporterCreator = getVsTelemetryReporterCreator(workspace.get<boolean>('enableTelemetry'));
Expand All @@ -15,6 +16,8 @@ const telemetryReporter = TelemetryReporterLocator.getReporter();
exports.activate = (context: vscode.ExtensionContext) => {
AppIntegrator.create(vscode as any, console).integrate(context);
context.subscriptions.push(telemetryReporter);

initAutoHighlight(context)
};

exports.deactivate = () => {
Expand Down
6 changes: 5 additions & 1 deletion src/lib/colour-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ export default class ColourRegistry {
issue(): string {
const colours = this.configStore.highlightColors;
const availableColour = colours.find(colour => !this.inUseColours.includes(colour));
const newColour = availableColour || this.configStore.defaultHighlightColor;
const newColour = availableColour || this.randomColor()
this.inUseColours = this.inUseColours.concat(newColour);
return newColour;
}

randomColor() {
return '#'+Math.random().toString(16).slice(-6)
}

reserve(colour: string): void {
const addend = this.inUseColours.includes(colour) ? [] : [colour];
this.inUseColours = [...this.inUseColours, ...addend];
Expand Down
4 changes: 0 additions & 4 deletions src/lib/config-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ export default class ConfigStore {
return this.get<string[]>('highlightColors');
}

get defaultHighlightColor() {
return this.get<string>('defaultHighlightColor');
}

get defaultHighlightOpacity() {
return this.get<string>('defaultHighlightOpacity');
}
Expand Down
20 changes: 12 additions & 8 deletions src/lib/config-target-picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as O from 'fp-ts/lib/Option';
import {getOptionM} from 'fp-ts/lib/OptionT';
import {Task, task} from 'fp-ts/lib/Task';
import WindowComponent, {QuickPickItem} from './vscode/window';
import {workspace} from 'vscode'

const ConfigurationTarget = {
GLOBAL: true,
Expand All @@ -27,16 +28,19 @@ export default class ConfigurationTargetPicker {
}

private buildQuickPickItems(): ConfigurationTargetQuickPickItem[] {
return [
{
label: 'Global',
value: ConfigurationTarget.GLOBAL
},
{
let arr = [{
label: 'Global',
value: ConfigurationTarget.GLOBAL
}]

workspace.rootPath
? arr.push({
label: 'Workspace',
value: ConfigurationTarget.WORKSPACE
}
];
})
: arr

return arr;
}

}
1 change: 0 additions & 1 deletion src/test/unit/colour-registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ suite('ColourRegistry', () => {
suite('When no colours are left unused', () => {
const configStore = mockType<ConfigStore>({
highlightColors: [],
defaultHighlightColor: 'DEFAULT_COLOUR'
});
const colourRegistry = new ColourRegistry(configStore);

Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,11 @@ locate-path@^3.0.0:
p-locate "^3.0.0"
path-exists "^3.0.0"

lodash.debounce@^4.0.8:
version "4.0.8"
resolved "https://registry.yarnpkg.com/lodash.debounce/-/lodash.debounce-4.0.8.tgz#82d79bff30a67c4005ffd5e2515300ad9ca4d7af"
integrity sha1-gteb/zCmfEAF/9XiUVMArZyk168=

locate-path@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-5.0.0.tgz#1afba396afd676a6d42504d0a67a3a7eb9f62aa0"
Expand Down