Skip to content

Commit

Permalink
Merge pull request #25 from noir017/master
Browse files Browse the repository at this point in the history
修复csv定义的元数据有空行和省略的时候会报错的问题
  • Loading branch information
lz37 authored Dec 24, 2024
2 parents 8e02d0b + 82c234c commit f9cdad7
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 8 deletions.
72 changes: 72 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,75 @@
## 1.4.9 (2024-12-24)


### Bug Fixes

* 。in smaple ([aaeadbd](https://github.com/lz37/noveler/commit/aaeadbd12ac9cd0c4e9c9ecdce8a865b2da3ea16))
* 错别字 ([e401667](https://github.com/lz37/noveler/commit/e4016678e628cfd061381dbb75066858fa3a88a3))
* action ([df87fa2](https://github.com/lz37/noveler/commit/df87fa2fb485d78942434b597faad4b230daa151))
* action ([8a07f09](https://github.com/lz37/noveler/commit/8a07f092a3d609a641b059cdb95f7752816366f4))
* alittle ([6ac297b](https://github.com/lz37/noveler/commit/6ac297ba4687aad8eebd2c5d1944809a7086ae12))
* async panel & win path ([bb8727a](https://github.com/lz37/noveler/commit/bb8727a5e7508c814611bf4da1a13db5deab641d))
* change behavior of default highlight & fix bug of completion ([2487544](https://github.com/lz37/noveler/commit/248754445b4e7f9df4d820747db83cf8d907ef31))
* changelog ([1eb4d75](https://github.com/lz37/noveler/commit/1eb4d752e544befe75702efb337efcb4df1361fa))
* changelog ([4c1ec10](https://github.com/lz37/noveler/commit/4c1ec10477bd5b6588bfb8bb4453d3a0cad69c7e))
* **changelog:** change log ([72c69c0](https://github.com/lz37/noveler/commit/72c69c0f4f481c8ba98eafe0b74e5c0dab58953a))
* **ci & changelog:** change ci & changelog ([439dc2b](https://github.com/lz37/noveler/commit/439dc2b9a37d255df18dc42a05f14037db4fee3a))
* **ci:** ci ([380a8c9](https://github.com/lz37/noveler/commit/380a8c96ac1dc6e4b18064cd2d3b01a722d6a2da))
* **ci:** edit ci cd ([0b9f85c](https://github.com/lz37/noveler/commit/0b9f85c392b642326e133ff18214b946aa1df028))
* csv定义的元数据允许空行和省略 ([4ab412d](https://github.com/lz37/noveler/commit/4ab412d44c0206f1dc644e6920c9f99759934702))
* csv定义的元数据允许空行和省略 ([00f92a1](https://github.com/lz37/noveler/commit/00f92a1d641adf20edd829504cdd3ffa63e92b6e))
* **csvreader.ts:** solve bug of failing to show default highlight when no csv settings ([ac29c89](https://github.com/lz37/noveler/commit/ac29c89d8437c111fe99077433c8a55b2e71d231))
* debug script ([c3a31a9](https://github.com/lz37/noveler/commit/c3a31a9036cfca0003adc2a4bff0218fdf284948))
* delete data gened in test csv ([094e9fb](https://github.com/lz37/noveler/commit/094e9fb5465208f3d30c4389d4d62a15f6d68cf1))
* **diagnostic.ts:** deal with empty string ([9b6d5ff](https://github.com/lz37/noveler/commit/9b6d5ff46a1f028f6549ae97e31685b3fd4c1362))
* fix about file dir & outline of outline file ([55d35a1](https://github.com/lz37/noveler/commit/55d35a1fd12154f3ba89d11ad86215b0bb4e334b))
* fix Indention ([7f01769](https://github.com/lz37/noveler/commit/7f017693e9952566f482fb873d4444e8ec9ecb6f))
* open all statusItems in default ([4b3ddf3](https://github.com/lz37/noveler/commit/4b3ddf3a915f09182c78824f249254d8b09b7c0d))
* **package.json:** change changelog command ([ec3e5c7](https://github.com/lz37/noveler/commit/ec3e5c7c00de53dde82ee5ee6bfc9593be7885ec))
* **package.json:** edit change parameters ([0b5e8b3](https://github.com/lz37/noveler/commit/0b5e8b3663eb2636adc7b506a3051d71c949e41c))
* **package:** changelog command ([4ca3fed](https://github.com/lz37/noveler/commit/4ca3feda45689246385eda7537e98cf89691695f))
* **package:** delete preversion script ([81553ad](https://github.com/lz37/noveler/commit/81553ad42472567f6539052f6dd5ca1c1cb357d1))
* **package:** version -> preversion ([27ccdbf](https://github.com/lz37/noveler/commit/27ccdbfd09ee07788a8a971c6df81f7425b2e833))
* **panel:** panel color in dark mode ([4153747](https://github.com/lz37/noveler/commit/41537478a60810fb98a3955f605e73c7c2e85784))
* prettierrc ([d05d1a0](https://github.com/lz37/noveler/commit/d05d1a0717f363dcfef325925b970523028d84a0))
* readme ([ba1530d](https://github.com/lz37/noveler/commit/ba1530d355891d6fe09338ac7628fba6c4b514b1))
* stricten the onChangeConf hook ([20b40e7](https://github.com/lz37/noveler/commit/20b40e77ede217c8bfbe54a2cd41edd8dd5fd8bd))
* version script ([beb569d](https://github.com/lz37/noveler/commit/beb569d7a3283317cfdc19ea931658583beba583))
* version script ([b42490a](https://github.com/lz37/noveler/commit/b42490aa0264a15c7094aadab49dc2a0c706bb6f))
* version script ([6bb5171](https://github.com/lz37/noveler/commit/6bb5171a9edc34b6edfac4ebaed510daf3030afe))
* version script ([93e9b9f](https://github.com/lz37/noveler/commit/93e9b9fad9d2d38b0fadd572578cd32a9147c923))
* version script ([e997d5f](https://github.com/lz37/noveler/commit/e997d5fd001e68a244925782625b5a707f3d185f))
* version script ([f7c68a0](https://github.com/lz37/noveler/commit/f7c68a06c40e41e78e6e323092a2144db4fec902))
* version script ([f8d5a4f](https://github.com/lz37/noveler/commit/f8d5a4f8b7aa71b03fad95ba8a17670c514fea1a))
* **version:** version script ([198a512](https://github.com/lz37/noveler/commit/198a512b3ca01e08ad34529a19521a10d337e0fa))
* **version:** versionscript ([5602e3f](https://github.com/lz37/noveler/commit/5602e3f0fced10e5a944a18710597b0e5d9d21a5))
* word count bug ([e43f117](https://github.com/lz37/noveler/commit/e43f117b41c6c8dd8b6a3de6da87a7834d9c5c73))
* **workflows:** fix cicd path ([c3aa24b](https://github.com/lz37/noveler/commit/c3aa24b35e49954d595f0d1c66faa7b02ccd4545))


### Features

* add comment from sample ([2e1af64](https://github.com/lz37/noveler/commit/2e1af64579d9d9e0438f3cd731b029a81f267dd7))
* add lint-staged ([fbd2a86](https://github.com/lz37/noveler/commit/fbd2a863c0d82d67694cf2bb5fccd5ac4f09c5ee))
* **app & panel:** add router in app module & sidebar panel in extension ([60b2682](https://github.com/lz37/noveler/commit/60b2682677e2ec2aad18ead2965a52d1013b5985))
* completion ([8fd24c3](https://github.com/lz37/noveler/commit/8fd24c3f58c5845f9e51fe149538650475a66e4b))
* deal with scrollbar & responsive ([1a0fed4](https://github.com/lz37/noveler/commit/1a0fed452a7dc731d4463d2edce6835a8a8148fd))
* diagnostic ([c352a88](https://github.com/lz37/noveler/commit/c352a88b7ee447a03e19cda6add3935a541c5301))
* doc, panel outlook, keywords, readme, conf recommand ([f567509](https://github.com/lz37/noveler/commit/f567509eb778e5c31801d7e9a37f1243f69b3cc9))
* github actions ([d044ae1](https://github.com/lz37/noveler/commit/d044ae120c5a51627bc7f690091adf404b24c9af))
* outline in panel ([5d4d412](https://github.com/lz37/noveler/commit/5d4d412edb8872efe5b4430177cec5d34c3bca7c))
* **package:** add install script ([838d413](https://github.com/lz37/noveler/commit/838d4131746acad5787482ef37f0860a5a647987))
* **panel:** success add panel, and change webview html to control router ([e64af0c](https://github.com/lz37/noveler/commit/e64af0c529a2023bb5ca6bc9ff00afc2a6cab65d))
* update status bar ([afd292c](https://github.com/lz37/noveler/commit/afd292cddaf097e9dbb45acfbc6cba8e14a20e84))
* **webpack:** optimize ([88b2803](https://github.com/lz37/noveler/commit/88b28034147bb9bb668a7c0e8a1a13bd1d7c10ca))


### Reverts

* **version:** delete version script ([7b0f0bb](https://github.com/lz37/noveler/commit/7b0f0bb9dc0887ec86577e5a02c70e4fafc79158))



## [1.4.8](https://github.com/lz37/noveler/compare/v1.4.5...v1.4.8) (2023-12-25)


Expand Down
6 changes: 5 additions & 1 deletion docs/description.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 修改

-添加statusWordReset设置选项,允许切换文件时不重置字数(默认为不重置)

## bug修复

- 修复了配置文件被重复读取的部分问题(针对大文件优化)
-修复csv定义的元数据有空行和省略报错的问题
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "noveler",
"displayName": "Noveler",
"description": "一个在 vscode 上辅助码中文小说的插件",
"version": "1.4.8",
"version": "1.4.9",
"author": "zerozawa",
"publisher": "zerozawa",
"license": "GPL-3.0",
Expand Down Expand Up @@ -211,6 +211,12 @@
"markdownDescription": "状态栏字数统计是否包含空格",
"scope": "resource"
},
"noveler.statusWordReset": {
"type": "boolean",
"default": false,
"markdownDescription": "切换文件时是否重置字数统计",
"scope": "resource"
},
"noveler.statusTimeUnit": {
"type": "number",
"default": 10,
Expand Down
1 change: 1 addition & 0 deletions packages/common/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export interface IConfig {
statusShow: boolean
statusTimeUnit: number
statusIncludingSpace: boolean
statusWordReset: boolean
statusItems: StatusItem[]
previewFontSize: number
previewIndentionLength: number
Expand Down
16 changes: 14 additions & 2 deletions packages/extension/src/modules/StatusBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const statusItem = vscode.window.createStatusBarItem(
let startLength = 0
let textItems: StatusItem[] = []
let includingSpace = false
let wordReset = false
let inputLength = 0
let isShow = false
let accumulateTime = 0
Expand Down Expand Up @@ -53,11 +54,17 @@ const updateItemTooltip = (sum: number, textLength: number) => {
}

const updateConf = () => {
const { statusShow, statusTimeUnit, statusIncludingSpace, statusItems } =
confHandler.get()
const {
statusShow,
statusTimeUnit,
statusIncludingSpace,
statusItems,
statusWordReset,
} = confHandler.get()
isShow = statusShow
timeUnit = statusTimeUnit
includingSpace = statusIncludingSpace
wordReset = statusWordReset
textItems = statusItems
if (vscode.window.activeTextEditor) {
startLength = textLengthHandler(vscode.window.activeTextEditor.document)
Expand Down Expand Up @@ -135,6 +142,11 @@ export const changeEditor = vscode.window.onDidChangeActiveTextEditor(
if (!editor) return
if (!targetFiles.includes(editor.document.languageId)) return
startLength = textLengthHandler(editor.document)

if (!wordReset) {
// 是否开启重置切换文件重置字数
startLength -= inputLength // 如果不重置那么开始位置就要减去上次输入的字数
}
updateItemTooltip(inputLength, startLength)
},
)
Expand Down
21 changes: 18 additions & 3 deletions packages/extension/src/modules/reader/CSVReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ const handleCSV = async (csvOpt: CSVOptions) => {
// 读取
try {
const data = await fs.readFile(csvOpt.path, 'utf-8')
const records: string[][] = parse(data)
// 添加relax_column_count属性,支持空行,每行列数不同的csv
const records: string[][] = parse(data, { relax_column_count: true })
const firstRow = records[0]
let keyIndex = -1
let hoverKeyIndex = -1
Expand All @@ -73,14 +74,28 @@ const handleCSV = async (csvOpt: CSVOptions) => {
hoverKeyIndex = i
}
}

if (keyIndex === -1) {
throw new Error(`配置文件 ${csvOpt.path} 中没有找到 key: ${csvOpt.key}`)
}
const datas = records.slice(1)

datas.forEach((row) => {
const key = row[keyIndex].trim()
let key = row[keyIndex]
// 跳过空白行或未定义行
if (key) {
key = key.trim()
} else {
return
}
if (csvOpt.hoverKey && hoverKeyIndex !== -1) {
const hover = row[hoverKeyIndex].trim()
let hover = row[hoverKeyIndex]
// 解决hoverKey空白报错
if (hover) {
hover = hover.trim()
} else {
hover = key // 如果没有填信息,则设置为key
}
completion.setKeys(key, csvOpt.suggestPrefix, hover, csvOpt.suggestKind)
const editor = vscode.window.activeTextEditor
if (!editor) return
Expand Down
8 changes: 7 additions & 1 deletion test/folder1/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"noveler.autoIndentLines": 1,
"noveler.spaceBetweenChEn": true,
"noveler.statusShow": true,
"noveler.statusWordReset": false,
"noveler.statusTimeUnit": 10,
"noveler.previewFontSize": 18,
"noveler.previewIndentionLength": 4,
Expand All @@ -19,5 +20,10 @@
"hoverKey": "信息",
"decorationRenderOptions": { "color": "#9e952f" }
}
]
],
"[plaintext]": {
"editor.wrappingIndent": "none",
"editor.autoIndent": "none",
"editor.wordWrap": "bounded"
}
}
2 changes: 2 additions & 0 deletions test/folder1/.vscode/test.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
名称,信息
试试,**sd**

0 comments on commit f9cdad7

Please sign in to comment.