From 28b9d92aca2a300bac34b8b36c5741ac0368ffab Mon Sep 17 00:00:00 2001 From: alexzhang1030 <1642114555@qq.com> Date: Mon, 8 Jan 2024 17:57:20 +0800 Subject: [PATCH 1/3] feat(leap): support dim when searching --- README.md | 2 ++ package.json | 12 ++++++++++- src/actions/plugins/leap/LeapAction.ts | 1 + src/actions/plugins/leap/leap.ts | 28 +++++++++++++++++++++++++- src/configuration/configuration.ts | 2 ++ src/configuration/iconfiguration.ts | 2 ++ test/testConfiguration.ts | 4 +++- 7 files changed, 48 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1026c53c..e4c2381f 100644 --- a/README.md +++ b/README.md @@ -536,6 +536,8 @@ Based on [vim-leap](https://github.com/ggandor/leap.nvim) and configured through | vim.leap.bidirectionalSearch | Enable/disable bidirectional search | Boolean | false | | | vim.leap.marker.backgroundColors | The background colors of the marker box. | Array | ['#ccff88', '#99ccff'] | | vim.leap.marker.charColor | The color of the marker char. | String | "#000000" | +| vim.leap.dim | Enable/Disable dim for leap | Boolean | true "#777777" | +| vim.leap.dimColor | The dim color | String | "#777777" | Once leap is active, initiate motions using the following commands.After you initiate the motion, text decorators/markers will be displayed and you can press the keys displayed to jump to that position. For visual mode leap uses x instead of s because s is already taken by the surround plugin. diff --git a/package.json b/package.json index 14766edf..ddadd20b 100644 --- a/package.json +++ b/package.json @@ -659,6 +659,16 @@ "markdownDescription": "The color of the marker char", "default": "#000000" }, + "vim.leap.dim": { + "type": "boolean", + "default": true, + "markdownDescription": "Enable the dimming of characters when using Leap" + }, + "vim.leap.dimColor": { + "type": "string", + "default": "#777777", + "markdownDescription": "Set a custom color for the leap dimmed characters when `#vim.leap.dim#` is set to true." + }, "vim.easymotion": { "type": "boolean", "markdownDescription": "Enable the [EasyMotion](https://github.com/easymotion/vim-easymotion) plugin for Vim.", @@ -1238,4 +1248,4 @@ "*.{ts,js,json,md,yml}": "prettier --write", "*.ts": "tslint --fix" } -} \ No newline at end of file +} diff --git a/src/actions/plugins/leap/LeapAction.ts b/src/actions/plugins/leap/LeapAction.ts index d6208318..8c6b43cf 100644 --- a/src/actions/plugins/leap/LeapAction.ts +++ b/src/actions/plugins/leap/LeapAction.ts @@ -47,6 +47,7 @@ export class LeapPrepareAction extends BaseCommand { ); leap.showMarkers(); + leap.setDimmingZones(); await vimState.setCurrentMode(Mode.LeapPrepareMode); } diff --git a/src/actions/plugins/leap/leap.ts b/src/actions/plugins/leap/leap.ts index 85896832..94e50f7b 100644 --- a/src/actions/plugins/leap/leap.ts +++ b/src/actions/plugins/leap/leap.ts @@ -5,6 +5,7 @@ import { VimState } from '../../../state/vimState'; import { LeapAction } from './LeapAction'; import { Position } from 'vscode'; import { configuration } from '../../../configuration/configuration'; +import * as vscode from 'vscode'; export enum LeapSearchDirection { Forward = -1, @@ -21,6 +22,10 @@ export class Leap { direction?: LeapSearchDirection; leapAction?: LeapAction; firstSearchString?: string; + dimmingZone = vscode.window.createTextEditorDecorationType({ + // to prevent empty string of dimColor + color: configuration.leap.dimColor || '#777777', + }); constructor(vimState: VimState) { this.vimState = vimState; @@ -37,6 +42,21 @@ export class Leap { return this.markers; } + public setDimmingZones() { + if (!configuration.leap.dim) return; + const dimmingZones: vscode.DecorationOptions[] = []; + const dimmingRenderOptions: vscode.ThemableDecorationRenderOptions = { + // we update the color here again in case the configuration has changed + color: configuration.leap.dimColor || '#777777', + }; + dimmingZones.push({ + // fill the whole document + range: new vscode.Range(0, 0, this.vimState.editor.document.lineCount, 0), + renderOptions: dimmingRenderOptions, + }); + this.vimState.editor.setDecorations(this.dimmingZone, dimmingZones); + } + private setMarkersName() { const map: Map = new Map(); @@ -147,6 +167,11 @@ export class Leap { this.markers = []; } + public cleanupDimmingZones() { + if (!configuration.leap.dim) return; + this.vimState.editor.setDecorations(this.dimmingZone, []); + } + public showMarkers() { this.markers.forEach((marker) => { marker.show(); @@ -236,5 +261,6 @@ export function getLeapInstance(): Leap { } export function disposeLeap() { - leap?.cleanupMarkers() + leap?.cleanupMarkers(); + leap?.cleanupDimmingZones(); } diff --git a/src/configuration/configuration.ts b/src/configuration/configuration.ts index bdc8bfd4..9ce7eb8b 100644 --- a/src/configuration/configuration.ts +++ b/src/configuration/configuration.ts @@ -275,6 +275,8 @@ class Configuration implements IConfiguration { backgroundColors: ['#ccff88', '#99ccff'], charColor: '#000000', }, + dim: true, + dimColor: '#777777', }; targets: ITargetsConfiguration = { diff --git a/src/configuration/iconfiguration.ts b/src/configuration/iconfiguration.ts index d1d90dd2..c01330a9 100644 --- a/src/configuration/iconfiguration.ts +++ b/src/configuration/iconfiguration.ts @@ -96,6 +96,8 @@ export interface ILeapConfiguration { backgroundColors: string[]; charColor: string; }; + dim: boolean; + dimColor: string; } export interface IConfiguration { diff --git a/test/testConfiguration.ts b/test/testConfiguration.ts index c922c08e..cc743d8c 100644 --- a/test/testConfiguration.ts +++ b/test/testConfiguration.ts @@ -37,8 +37,10 @@ export class Configuration implements IConfiguration { bidirectionalSearch: false, marker: { backgroundColors: ['#ccff88', '#99ccff'], - charColor:"#000000" + charColor: '#000000', }, + dim: true, + dimColor: '#777777', }; surround = false; argumentObjectSeparators = [',']; From 4a334615acb50bb8f293370d90ac9eb3693189c8 Mon Sep 17 00:00:00 2001 From: alexzhang1030 <1642114555@qq.com> Date: Mon, 8 Jan 2024 17:59:37 +0800 Subject: [PATCH 2/3] docs: update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e4c2381f..1adb52b3 100644 --- a/README.md +++ b/README.md @@ -536,7 +536,7 @@ Based on [vim-leap](https://github.com/ggandor/leap.nvim) and configured through | vim.leap.bidirectionalSearch | Enable/disable bidirectional search | Boolean | false | | | vim.leap.marker.backgroundColors | The background colors of the marker box. | Array | ['#ccff88', '#99ccff'] | | vim.leap.marker.charColor | The color of the marker char. | String | "#000000" | -| vim.leap.dim | Enable/Disable dim for leap | Boolean | true "#777777" | +| vim.leap.dim | Enable/Disable dim for leap | Boolean | true | vim.leap.dimColor | The dim color | String | "#777777" | Once leap is active, initiate motions using the following commands.After you initiate the motion, text decorators/markers will be displayed and you can press the keys displayed to jump to that position. For visual mode leap uses x instead of s because s is already taken by the surround plugin. From 8d44bba76ade693bf2c206e6aa6476588172e12c Mon Sep 17 00:00:00 2001 From: alexzhang1030 <1642114555@qq.com> Date: Mon, 8 Jan 2024 18:04:31 +0800 Subject: [PATCH 3/3] docs: update --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1adb52b3..d664f22d 100644 --- a/README.md +++ b/README.md @@ -536,8 +536,8 @@ Based on [vim-leap](https://github.com/ggandor/leap.nvim) and configured through | vim.leap.bidirectionalSearch | Enable/disable bidirectional search | Boolean | false | | | vim.leap.marker.backgroundColors | The background colors of the marker box. | Array | ['#ccff88', '#99ccff'] | | vim.leap.marker.charColor | The color of the marker char. | String | "#000000" | -| vim.leap.dim | Enable/Disable dim for leap | Boolean | true -| vim.leap.dimColor | The dim color | String | "#777777" | +| vim.leap.dim | Enable/Disable dim for leap | Boolean | true | | +| vim.leap.dimColor | The dim color | String | "#777777" | | Once leap is active, initiate motions using the following commands.After you initiate the motion, text decorators/markers will be displayed and you can press the keys displayed to jump to that position. For visual mode leap uses x instead of s because s is already taken by the surround plugin.