Hide multiple lines
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 35/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- react, typescript
- 领域
- frontend
调研方向
该 issue 未提供 repository 文件或测试入口点;请从提供的 TypeScript foldLinesPlugin 及其 CodeMirror 装饰逻辑开始。完成的标准是仅显示匹配的行,同时保留其原始行号,并在编辑器中验证该行为。
由索引模型根据 Issue 内容生成。
描述
Hi 👋
I'm trying to build something like the GitHub code search
Example
For now I'm able to highlight words based on start and end index:
Code
const getDecorations = (
highlights: Array<{ start: number; end: number }> = []
) => {
const decorations = highlights.map(({ start, end }) =>
Decoration.mark({
attributes: { style: "background-color: #dadb1699" },
}).range(start, end)
);
return Decoration.set(decorations);
};
export const highlightPlugin = (
highlights: Array<{ start: number; end: number }>
) =>
ViewPlugin.fromClass(
class {
decorations: DecorationSet;
constructor() {
this.decorations = getDecorations(highlights);
}
update(update: ViewUpdate) {
if (update.docChanged || update.viewportChanged) {
this.decorations = getDecorations();
}
}
},
{
decorations: (v) => v.decorations,
}
);
const pointIsInRanges = (point: number, start: number, end: number) => point >= start && point <= end
export const foldLinesPlugin = (
rangesToKeep: { start: number; end: number }[]
): ViewPlugin<{ decorations: DecorationSet }> => {
return ViewPlugin.fromClass(
class {
decorations: DecorationSet;
constructor(view: EditorView) {
this.decorations = this.foldLines(view);
}
update(update: ViewUpdate) {
if (update.docChanged || update.viewportChanged) {
this.decorations = this.foldLines(update.view);
}
}
foldLines(view: EditorView): DecorationSet {
const builder = new RangeSetBuilder<Decoration>();
const lines = view.state.doc.lines;
for (let i = 1; i <= lines; i++) {
const line = view.state.doc.line(i);
let found = false;
for (const range of rangesToKeep) {
if (
pointIsInRanges(range.start, line.from, line.to) ||
pointIsInRanges(range.end, line.from, line.to)
) {
found = true;
break;
}
}
if (!found) {
builder.add(
line.from,
line.to,
Decoration.replace({ widget: new FoldWidget() })
);
}
}
return builder.finish();
}
},
{
decorations: (v) => v.decorations,
}
);
};
class FoldWidget extends WidgetType {
toDOM() {
const span = document.createElement("span");
span.style.display = "none";
return span;
}
}
How can I just show only the match result without all other lines and how can I keep the only the original line number?
- 主要语言
- TypeScript
- 星标
- 2.3k
- 派生
- 162
- 平均合并
- 2 小时 41 分钟
- 30 天内合并 PR
- 1
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
uiwjs/react-codemirror 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 64/100
uiwjs/react-codemirror#766 · 2 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 68/100
uiwjs/react-codemirror#765 ·
-
难度 3/5 1-2 天 新手友好度 35/100
uiwjs/react-codemirror#772 ·
-
难度 4/5 3-5 天 新手友好度 48/100
uiwjs/react-codemirror#770 ·
-
难度 3/5 1-2 天 新手友好度 48/100
uiwjs/react-codemirror#767 · 2 条评论 ·
查看 uiwjs/react-codemirror 的全部 Issue
相似的 Issue
-
area: repo priority: P2 type: bug
难度 2/5 1-3 小时 新手友好度 76/100
appandflow/stim#4107 · 1 条评论 ·
维护者通常 1 天内回复
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
难度 1/5 1-3 小时 新手友好度 60/100
lingdojo/kana-dojo#32859 · 1 条评论 · 5 个 reaction ·
维护者通常 1 天内回复
-
code-quality refactoring
难度 2/5 1-3 小时 新手友好度 78/100
github/gh-aw-firewall#10364 ·
维护者通常 1 天内回复
-
Merge the duplicate kaffir_corn record into sorghum可能已有人在做 @Crypto-Shroom 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 65/100
Crypto-Shroom/Bird-Feed-Calculator#322 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
drizzle-team/drizzle-orm#6552 ·
维护者通常 2 天内回复