Skip to content

Commit c5f8f05

Browse files
committed
fix(bookmarkcolor): 修复书签颜色配置调整渲染不生效问题
1 parent e3b3ddd commit c5f8f05

File tree

14 files changed

+175
-109
lines changed

14 files changed

+175
-109
lines changed

.changeset/chilly-games-boil.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'bookmark-manager': patch
3+
---
4+
5+
fix(bookmarkcolor): 修复书签颜色配置调整渲染不生效问题

package.nls.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"bookmark-manager.textDecorationThickness.description": "Text decoration thickness",
3131
"bookmark-manager.lineBlame.description": "Enable Line Blame",
3232
"bookmark-manager.fontWeight.description": "Font Weight",
33-
"bookmark-manager.colors.description": "Custom bookmark color, object format: {\" name\": \"value\"}",
33+
"bookmark-manager.colors.description": "Custom bookmark color, object format: {\" name\": \"value\"}.Note that this color value should be in hexadecimal format as much as possible. This makes it easier for the plugin to have a transparent effect when highlighting the current bookmark line, so that the current line content will not be unclear after it is turned on.",
3434
"bookmark-manager.defaultBookmarkIconColor.description": "The default color of bookmark icon.",
3535
"bookmark-manager.enableClick.description": "Enable click to jump to bookmark location",
3636
"bookmark-manager.viewsWelcome.content": "Add some bookmarks",
@@ -78,4 +78,4 @@
7878
"bookmark-manager.defaultLabeledBookmarkIcon.description": "Default labeled bookmark icon",
7979
"bookmark-manager.defaultBookmarkIcon.description": "Default bookmark icon",
8080
"bookmark-manager.icons.description": "Custom icon list, `key` is the custom icon name, `value` format is `prefix:name`, which is the `iconify` website icon name format. for example: 'mdi:bookmark'"
81-
}
81+
}

package.nls.zh.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"bookmark-manager.textDecorationThickness.description": "设置用于装饰的线条粗细",
3131
"bookmark-manager.lineBlame.description": "是否跟随鼠标位置显示书签信息",
3232
"bookmark-manager.fontWeight.description": "书签字体权重",
33-
"bookmark-manager.colors.description": "设置书签的颜色",
33+
"bookmark-manager.colors.description": "设置书签的颜色.注意, 这个颜色值尽量使用16进制格式,.这样方便插件在使用高亮当前书签所在行的时候可以有个透明的效果,不至于导致开启后导致看不清当前行的内容",
3434
"bookmark-manager.defaultBookmarkIconColor.description": "默认书签图标的颜色",
3535
"bookmark-manager.enableClick": "启用双击跳转到书签位置",
3636
"bookmark-manager.viewsWelcome.content": "增加一些书签",
@@ -78,4 +78,4 @@
7878
"bookmark-manager.defaultLabeledBookmarkIcon.description": "打上标签的书签的默认图标",
7979
"bookmark-manager.defaultBookmarkIcon.description": "书签的默认图标",
8080
"bookmark-manager.icons.description": "自定义图标列表,`key`为自定义图标名称,`value`格式为`prefix:name`,即`iconify`网站图标名称格式.例如: 'mdi:bookmark'"
81-
}
81+
}

src/constants/colors.ts

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,36 @@
1-
export const defaultColors = {
2-
red: 'red',
3-
green: 'green',
4-
blue: 'blue',
5-
white: 'white',
6-
yellow: 'yellow',
7-
orange: 'orange',
8-
purple: 'purple',
9-
black: 'black',
1+
export const defaultColors: { [name: string]: { value: string, hex: string } } = {
2+
red: {
3+
value: 'red',
4+
hex: '#ff0000'
5+
},
6+
green: {
7+
value: 'green',
8+
hex: '#008000'
9+
},
10+
blue: {
11+
value: 'blue',
12+
hex: '#2196F3'
13+
},
14+
white: {
15+
value: 'white',
16+
hex: '#0000ff'
17+
},
18+
yellow: {
19+
value: 'yellow',
20+
hex: '#FFD700'
21+
},
22+
orange: {
23+
value: 'orange',
24+
hex: '#FF9800'
25+
},
26+
purple: {
27+
value: 'purple',
28+
hex: '#9C27B0'
29+
},
30+
black: {
31+
value: 'black',
32+
hex: '#212121'
33+
}
1034
};
1135
/**
1236
* 默认的书签的颜色标签

src/services/ConfigService.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export default class ConfigService extends BaseService {
4949
get decorationConfiguration() {
5050
return this.configure.decoration;
5151
}
52+
5253
get configuration() {
5354
return this.configure.configure;
5455
}

src/services/DecorationService.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import {
66
TextEditorDecorationType,
77
window,
88
} from 'vscode';
9-
import {ServiceManager} from './ServiceManager';
10-
import {resolveBookmarkController} from '../bootstrap';
9+
import { ServiceManager } from './ServiceManager';
10+
import { resolveBookmarkController } from '../bootstrap';
1111
import BookmarksController from '../controllers/BookmarksController';
12-
import {Bookmark, IBookmark} from '../stores/bookmark';
13-
import {BaseService} from './BaseService';
14-
import {DEFAULT_BOOKMARK_COLOR} from '../constants';
15-
import {Instance} from 'mobx-state-tree';
12+
import { Bookmark, IBookmark } from '../stores/bookmark';
13+
import { BaseService } from './BaseService';
14+
import { DEFAULT_BOOKMARK_COLOR } from '../constants';
15+
import { Instance } from 'mobx-state-tree';
1616

1717
/**
1818
* 装饰器服务类
@@ -107,7 +107,7 @@ export default class DecorationService extends BaseService {
107107
}
108108

109109
createTextDecoration(bookmark: IBookmark) {
110-
let color = bookmark.plainColor || DEFAULT_BOOKMARK_COLOR;
110+
let { isHex, value: color } = bookmark.hexColor;
111111

112112
const {
113113
fontWeight,
@@ -129,7 +129,7 @@ export default class DecorationService extends BaseService {
129129
let overviewRulerColor;
130130
let overviewRulerLane: OverviewRulerLane | undefined = undefined;
131131
if (showGutterInOverviewRuler) {
132-
overviewRulerColor = bookmark.plainColor;
132+
overviewRulerColor = color;
133133
overviewRulerLane = OverviewRulerLane.Center;
134134
} else {
135135
overviewRulerColor = undefined;
@@ -147,9 +147,7 @@ export default class DecorationService extends BaseService {
147147
}
148148

149149
if (alwaysUseDefaultColor) {
150-
color =
151-
this.store.colors.find(it => it.label === 'default')?.value ||
152-
DEFAULT_BOOKMARK_COLOR;
150+
color = this.store.colors.get('deault')?.value || DEFAULT_BOOKMARK_COLOR;
153151
}
154152

155153
let rangeBehavior = DecorationRangeBehavior.ClosedClosed;

src/services/FileService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class FileService extends BaseService {
1616
os.homedir(),
1717
os.platform() === 'win32'
1818
? '.bookmark-manager'
19-
: './config/.bookmark-manager',
19+
: './.config/bookmark-manager',
2020
);
2121
this.checkDirIsExists(_path);
2222
return _path;

src/services/IconsService.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import {ServiceManager} from './ServiceManager';
2-
import {ofetch} from 'ofetch';
1+
import { ServiceManager } from './ServiceManager';
2+
import { ofetch } from 'ofetch';
33
import {
44
iconfiy_public_url,
55
iconify_collection_endpoint,
66
} from '../constants/icons';
7-
import {IconifyIconsType} from '../types/icon';
8-
import {BaseService} from './BaseService';
9-
import {applySnapshot, IDisposer, onSnapshot} from 'mobx-state-tree';
10-
import {EventEmitter, Uri, window, workspace} from 'vscode';
11-
import {escapeColor} from '../utils';
12-
import {EXTENSION_ID} from '../constants';
13-
import {IconType} from '../stores';
7+
import { IconifyIconsType } from '../types/icon';
8+
import { BaseService } from './BaseService';
9+
import { applySnapshot, IDisposer, onSnapshot } from 'mobx-state-tree';
10+
import { EventEmitter, Uri, window, workspace } from 'vscode';
11+
import { escapeColor } from '../utils';
12+
import { EXTENSION_ID } from '../constants';
13+
import { IconType } from '../stores';
1414

1515
/**
1616
* @zh 装饰器和树上的图标服务类
@@ -41,7 +41,7 @@ export class IconsService extends BaseService {
4141
// 监听插件的的`icons`的变化, 更新存储
4242
this._disposers.push(
4343
onSnapshot(this.configure.configure.icons, snapshot => {
44-
const {defaultBookmarkIcon, defaultLabeledBookmarkIcon} =
44+
const { defaultBookmarkIcon, defaultLabeledBookmarkIcon } =
4545
this.configure.configure;
4646
Object.entries(snapshot).forEach(([key, value], index) => {
4747
if (!this.store.icons.find(it => it.id === value)) {
@@ -70,7 +70,7 @@ export class IconsService extends BaseService {
7070
ev.affectsConfiguration(`${EXTENSION_ID}.defaultBookmarkIcon`) ||
7171
ev.affectsConfiguration(`${EXTENSION_ID}.defaultLabeledBookmarkIcon`)
7272
) {
73-
const {defaultBookmarkIcon, defaultLabeledBookmarkIcon} =
73+
const { defaultBookmarkIcon, defaultLabeledBookmarkIcon } =
7474
this.configure.configure;
7575
if (!this.store.icons.find(it => it.id === defaultBookmarkIcon)) {
7676
this.downloadIcon(defaultBookmarkIcon, 'default:bookmark');
@@ -112,6 +112,10 @@ export class IconsService extends BaseService {
112112
const response = await this.download(
113113
`${iconfiy_public_url}/${prefix}.json?icons=${name}`,
114114
);
115+
if (response.name === 'FetchError') {
116+
window.showInformationMessage('Icon download failed!');
117+
return;
118+
}
115119
window.showInformationMessage('Icon downloaded successfully!');
116120
const svgBody = (response as IconifyIconsType).icons[name].body;
117121
this.store.addNewIcon(prefix, name, svgBody, customName);
@@ -176,7 +180,7 @@ export class IconsService extends BaseService {
176180
for (let [key, value] of iconsValues) {
177181
// 下载配置需要存在但不存在本地的图标数据
178182
if (!this.sm.store.icons.find(it => it.id === value)) {
179-
toDownloadIcons.push({key, value});
183+
toDownloadIcons.push({ key, value });
180184
}
181185
}
182186

@@ -206,7 +210,7 @@ export class IconsService extends BaseService {
206210
if (!configure) {
207211
return;
208212
}
209-
const {defaultBookmarkIcon, defaultLabeledBookmarkIcon} =
213+
const { defaultBookmarkIcon, defaultLabeledBookmarkIcon } =
210214
configure.configure;
211215

212216
await this.downloadIcon(defaultBookmarkIcon, 'default:bookmark');
@@ -239,7 +243,7 @@ export class IconsService extends BaseService {
239243
}
240244

241245
let color =
242-
this.store.colors.find(it => it.label === colorLabel)?.value ||
246+
this.store.colors.get(colorLabel)?.value ||
243247
this.configure.configure.defaultBookmarkIconColor;
244248

245249
color = color.startsWith('#') ? escapeColor(color) : color;

src/stores/bookmark-store.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
import {Instance, types} from 'mobx-state-tree';
2-
import {l10n, Uri, window, workspace, WorkspaceFolder} from 'vscode';
3-
import {generateUUID, sortBookmarks} from '../utils';
1+
import { Instance, types } from 'mobx-state-tree';
2+
import { l10n, Uri, window, workspace, WorkspaceFolder } from 'vscode';
3+
import { generateUUID, sortBookmarks } from '../utils';
44
import {
55
BookmarksGroupedByCustomType,
66
BookmarksGroupedByFileType,
77
TreeViewGroupEnum,
88
TreeViewSortedEnum,
99
TreeViewStyleEnum,
1010
} from '../types';
11-
import {registerExtensionCustomContextByKey} from '../context';
11+
import { registerExtensionCustomContextByKey } from '../context';
1212
import {
1313
BookmarksGroupedByColorType,
1414
BookmarksGroupedByWorkspaceType,
1515
IBookmark,
1616
Bookmark,
1717
BookmarksGroupedByIconType,
1818
} from './bookmark';
19-
import {BookmarkGroup, IBookmarkGroup} from './bookmark-group';
20-
import {DEFAULT_BOOKMARK_GROUP_ID} from '../constants/bookmark';
21-
import {isProxy} from 'util/types';
22-
import {LoggerService, ServiceManager} from '../services';
19+
import { BookmarkGroup, IBookmarkGroup } from './bookmark-group';
20+
import { DEFAULT_BOOKMARK_GROUP_ID } from '../constants/bookmark';
21+
import { isProxy } from 'util/types';
22+
import { LoggerService, ServiceManager } from '../services';
2323

2424
const BookmarkGroupData = types.model('BookmarkGroupData', {
2525
id: types.string,
@@ -166,7 +166,7 @@ export const BookmarksStore = types
166166

167167
if (!existed) {
168168
grouped.push({
169-
workspace: {...it.workspaceFolder, ...it.wsFolder},
169+
workspace: { ...it.workspaceFolder, ...it.wsFolder },
170170
files: [
171171
{
172172
bookmarks: [it],
@@ -364,7 +364,7 @@ export const BookmarksStore = types
364364

365365
const groupId = bookmark.groupId || DEFAULT_BOOKMARK_GROUP_ID;
366366

367-
const {defaultBookmarkIcon, defaultLabeledBookmarkIcon} =
367+
const { defaultBookmarkIcon, defaultLabeledBookmarkIcon } =
368368
sm.store.configure.configure;
369369
_bookmark = Bookmark.create({
370370
id: id || generateUUID(),
@@ -728,9 +728,9 @@ export const BookmarksStore = types
728728
/**
729729
* 已经通过之前groups字段实现
730730
*/
731-
function addCustomroupInfo(info: BookmarkGroupDataType) {}
731+
function addCustomroupInfo(info: BookmarkGroupDataType) { }
732732

733-
function afterCreate() {}
733+
function afterCreate() { }
734734

735735
return {
736736
add,

0 commit comments

Comments
 (0)