Skip to content

Commit 6a96dc8

Browse files
committed
feat: expose cut for search
1 parent b4411c5 commit 6a96dc8

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/chsp-main.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Platform, Plugin } from "obsidian";
33
import { VimPatcher } from "./chsp-vim.js";
44
import setupCM6 from "./cm6";
55
import GoToDownloadModal from "./install-guide";
6-
import { cut, initJieba } from "./jieba";
6+
import { cut, cutForSearch, initJieba } from "./jieba";
77
import { ChsPatchSettingTab, DEFAULT_SETTINGS } from "./settings";
88
import { chsPatternGlobal, isChs } from "./utils.js";
99

@@ -120,10 +120,14 @@ export default class CMChsPatch extends Plugin {
120120
return true;
121121
}
122122

123-
cut(text: string): string[] {
123+
cut(text: string, { search = false }: { search?: boolean } = {}): string[] {
124124
if (!this.settings.useJieba && this.segmenter) {
125125
return Array.from(this.segmenter.segment(text)).map((seg) => seg.segment);
126-
} else return cut(text, this.settings.hmm);
126+
}
127+
if (search) {
128+
return cutForSearch(text, this.settings.hmm);
129+
}
130+
return cut(text, this.settings.hmm);
127131
}
128132

129133
getSegRangeFromCursor(

src/jieba.ts

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import init, {
22
add_word,
33
cut as jiebaCut,
4+
cut_for_search as jiebaCutForSearch,
45
} from "jieba-wasm/pkg/web/jieba_rs_wasm";
56

67
const vaildateFreq = (freq: string): number | undefined =>
@@ -45,6 +46,10 @@ export const cut = (text: string, hmm = false) => {
4546
if (!initialized) throw new Error("jieba not loaded");
4647
return jiebaCut(text, hmm);
4748
};
49+
export const cutForSearch = (text: string, hmm = false) => {
50+
if (!initialized) throw new Error("jieba not loaded");
51+
return jiebaCutForSearch(text, hmm);
52+
};
4853

4954
const vaildTags = {
5055
n: undefined, // 普通名词

0 commit comments

Comments
 (0)