diff --git a/crates/ide-core/src/editor_settings.rs b/crates/ide-core/src/editor_settings.rs index c0112b8dfa..17b2adfd41 100644 --- a/crates/ide-core/src/editor_settings.rs +++ b/crates/ide-core/src/editor_settings.rs @@ -33,6 +33,10 @@ pub struct EditorGeneralSettings { pub remove_trailing_blank_lines: bool, /// Copy as rich text (HTML with syntax colours) by default. pub rich_text_copy: bool, + /// Gutter › Highlight modified lines in the gutter: the VCS change bars next to the line numbers. + pub highlight_modified_lines: bool, + /// Gutter › Highlight modified lines in error stripe on the scrollbar (with `highlight_modified_lines`). + pub highlight_modified_lines_in_scrollbar: bool, } impl Default for EditorGeneralSettings { @@ -51,6 +55,8 @@ impl Default for EditorGeneralSettings { keep_trailing_on_caret_line: true, remove_trailing_blank_lines: false, rich_text_copy: true, + highlight_modified_lines: true, + highlight_modified_lines_in_scrollbar: true, } } } diff --git a/src/bindings.ts b/src/bindings.ts index 264f995a4a..a6638624af 100644 --- a/src/bindings.ts +++ b/src/bindings.ts @@ -6905,6 +6905,10 @@ export type EditorGeneralSettings = { removeTrailingBlankLines?: boolean, /** Copy as rich text (HTML with syntax colours) by default. */ richTextCopy?: boolean, + /** Gutter › Highlight modified lines in the gutter: the VCS change bars next to the line numbers. */ + highlightModifiedLines?: boolean, + /** Gutter › Highlight modified lines in error stripe on the scrollbar (with `highlight_modified_lines`). */ + highlightModifiedLinesInScrollbar?: boolean, }; /** diff --git a/src/editor/api.ts b/src/editor/api.ts index 7723920f1e..dbb507ae44 100644 --- a/src/editor/api.ts +++ b/src/editor/api.ts @@ -442,6 +442,19 @@ export const lineChanges = Facet.define values[0] ?? [], }); +/** + * Settings › Editor › General › Gutter: where the VCS change markers show. Set from the + * editor settings; the scrollbar marks follow the gutter setting, as in IDEA. + */ +export interface ChangeMarkerDisplay { + gutter: boolean; + scrollbar: boolean; +} + +export const changeMarkerDisplay = Facet.define({ + combine: (values) => values[0] ?? { gutter: true, scrollbar: true }, +}); + /** Marker for `gutterLaneMarkers`: a solid 3px bar (or a small wedge for `deleted`). */ export class LaneMarker extends GutterMarker { constructor( diff --git a/src/editor/core/cm/prefs.ts b/src/editor/core/cm/prefs.ts index 6bfdc80c4c..e184ec989e 100644 --- a/src/editor/core/cm/prefs.ts +++ b/src/editor/core/cm/prefs.ts @@ -36,7 +36,7 @@ import { import { markdownImages } from "./markdownImages"; import { selectionMarks } from "./selectionMarks"; import { seamlessSelection } from "./selectionLayer"; -import { useEditorRegistry } from "@/editor/api"; +import { changeMarkerDisplay, useEditorRegistry } from "@/editor/api"; import { editorPrefs, type EditorExtras } from "@/platform/editorSettings"; import { openideaHighlightStyle } from "./highlight"; import { @@ -818,6 +818,13 @@ export function prefsExtension(o: PrefsOptions): Extension { out.push(g.dragAndDrop ? textDrag : noTextDrag); if (g.caretScroll === "center") out.push(centerCaret); out.push(g.richTextCopy ? richCopyByDefault : plainCopyByDefault); + if (!g.highlightModifiedLines || !g.highlightModifiedLinesInScrollbar) + out.push( + changeMarkerDisplay.of({ + gutter: g.highlightModifiedLines, + scrollbar: g.highlightModifiedLines && g.highlightModifiedLinesInScrollbar, + }), + ); if (k.escapeOnPaste) out.push(stringClipboard(o.language)); if (!o.readOnly && (k.reformatOnPaste === "indentBlock" || k.reformatOnPaste === "indentEachLine")) out.push(pasteReindentFilter(k.reformatOnPaste)); diff --git a/src/features/settings/pages/editor/general.tsx b/src/features/settings/pages/editor/general.tsx index 655f146f0f..daedeff6b9 100644 --- a/src/features/settings/pages/editor/general.tsx +++ b/src/features/settings/pages/editor/general.tsx @@ -190,6 +190,23 @@ const GENERAL = editorPage({ }, ], }, + { + title: "Gutter", + items: [ + { + t: "check", + key: `${P}.general.highlightModifiedLines`, + label: "Highlight modified lines in the gutter", + children: [ + { + t: "check", + key: `${P}.general.highlightModifiedLinesInScrollbar`, + label: "Highlight modified lines in error stripe on the scrollbar", + }, + ], + }, + ], + }, { title: "Save Files", items: [ diff --git a/src/features/vcs/__tests__/hunks.test.ts b/src/features/vcs/__tests__/hunks.test.ts index 009e2c2d25..4a481ac29b 100644 --- a/src/features/vcs/__tests__/hunks.test.ts +++ b/src/features/vcs/__tests__/hunks.test.ts @@ -190,6 +190,29 @@ describe("change markers in folds", () => { }); }); +describe("change marker settings", () => { + it("hides the gutter bars and the scrollbar marks as Editor › General › Gutter says", async () => { + const { changeMarkerDisplay, gutterLaneMarkers, scrollbarMarks } = await import("@/editor/api"); + const { changeMarkers } = await import("../gutter"); + const shown = (display?: { gutter: boolean; scrollbar: boolean }) => { + const state = EditorState.create({ + doc: "a\nB\nc\n", + extensions: [ + changeMarkers({ path: "/p/f.txt" } as Parameters[0]), + display ? changeMarkerDisplay.of(display) : [], + ], + }).update({ effects: setHunksEffect.of([h("modified", 1, 1, 1, 1, "b\n")]) }).state; + return { + gutter: state.facet(gutterLaneMarkers).reduce((n, set) => n + set.size, 0), + scrollbar: state.facet(scrollbarMarks).length, + }; + }; + expect(shown()).toEqual({ gutter: 1, scrollbar: 1 }); + expect(shown({ gutter: true, scrollbar: false })).toEqual({ gutter: 1, scrollbar: 0 }); + expect(shown({ gutter: false, scrollbar: false })).toEqual({ gutter: 0, scrollbar: 0 }); + }); +}); + describe("hunkKeys", () => { it("identifies blocks by content, not position", () => { const a = hunkKeys("x\nB\nc\n", [h("modified", 1, 1, 1, 1, "b\n")]); diff --git a/src/features/vcs/gutter.ts b/src/features/vcs/gutter.ts index 82cfd84c10..1e39326576 100644 --- a/src/features/vcs/gutter.ts +++ b/src/features/vcs/gutter.ts @@ -11,6 +11,7 @@ import type { HunkKind, LineHunk } from "@/bindings"; import { call, commands, isTauri } from "@/platform/ipc"; import { LaneMarker, + changeMarkerDisplay, gutterLaneMarkers, lineChanges, scrollbarMarks, @@ -389,7 +390,13 @@ class HunkFetcher implements PluginValue { } } -function scrollMarks(state: EditorState): ScrollbarMark[] { +/** The lane markers, unless Settings › Editor › General › Gutter turns them off. */ +export function laneMarkers(state: EditorState): RangeSet { + return state.facet(changeMarkerDisplay).gutter ? visibleMarkers(state) : RangeSet.empty; +} + +export function scrollMarks(state: EditorState): ScrollbarMark[] { + if (!state.facet(changeMarkerDisplay).scrollbar) return []; return editorHunks(state).map((h) => ({ from: h.from, to: h.to > h.from ? h.to - 1 : h.from, @@ -466,8 +473,8 @@ export function changeMarkers(ctx: EditorDocContext): Extension { const path = ctx.path; return [ hunkField, - gutterLaneMarkers.compute([hunkField, foldState], visibleMarkers), - scrollbarMarks.compute([hunkField], scrollMarks), + gutterLaneMarkers.compute([hunkField, foldState, changeMarkerDisplay], laneMarkers), + scrollbarMarks.compute([hunkField, changeMarkerDisplay], scrollMarks), laneClicks(path), laneTheme, ViewPlugin.define((view) => new HunkFetcher(view, path)), diff --git a/src/platform/clientSettings.ts b/src/platform/clientSettings.ts index ca43fc9f40..400955577b 100644 --- a/src/platform/clientSettings.ts +++ b/src/platform/clientSettings.ts @@ -54,6 +54,8 @@ export const CLIENT_SETTINGS_KEYS = [ "editor.general.softWrapIndent", "editor.general.scrollPastEnd", "editor.general.richTextCopy", + "editor.general.highlightModifiedLines", + "editor.general.highlightModifiedLinesInScrollbar", "editor.codeStyle.visualGuides", "terminal.tabName", "terminal.appTitleAsTabName", diff --git a/src/platform/editorSettings.ts b/src/platform/editorSettings.ts index a91a80a00a..98c9723f4d 100644 --- a/src/platform/editorSettings.ts +++ b/src/platform/editorSettings.ts @@ -147,6 +147,9 @@ export const EDITOR_EXTRA_DEFAULTS = { keepTrailingOnCaretLine: true, removeTrailingBlankLines: false, richTextCopy: true, + /** Gutter › Highlight modified lines in the gutter / in error stripe on the scrollbar. */ + highlightModifiedLines: true, + highlightModifiedLinesInScrollbar: true, }, appearance: { caretBlinking: true, diff --git a/src/platform/locales/text/en.json b/src/platform/locales/text/en.json index 5e3efea155..7bda9fe359 100644 --- a/src/platform/locales/text/en.json +++ b/src/platform/locales/text/en.json @@ -4373,5 +4373,8 @@ "manage.py Tasks": "manage.py Tasks", "Install django-types to complete Django model fields and managers": "Install django-types to complete Django model fields and managers", "Installing django-types": "Installing django-types", - "Cannot install django-types": "Cannot install django-types" + "Cannot install django-types": "Cannot install django-types", + "Gutter": "Gutter", + "Highlight modified lines in the gutter": "Highlight modified lines in the gutter", + "Highlight modified lines in error stripe on the scrollbar": "Highlight modified lines in error stripe on the scrollbar" } diff --git a/src/platform/locales/text/zh-TW.json b/src/platform/locales/text/zh-TW.json index 5ada80a999..7819a8ce57 100644 --- a/src/platform/locales/text/zh-TW.json +++ b/src/platform/locales/text/zh-TW.json @@ -1671,6 +1671,9 @@ "Group by Severity": "按嚴重性分組", "Groups": "群組", "Gutter Icons": "裝訂區域圖示", + "Gutter": "裝訂區域", + "Highlight modified lines in the gutter": "在裝訂區域中醒目提示已修改的行", + "Highlight modified lines in error stripe on the scrollbar": "在捲軸的錯誤條紋中醒目提示已修改的行", "HACK comment": "HACK 註解", "HEAD (Current Branch)": "HEAD(目前分支)", "HTML 5 file": "HTML 5 檔案", diff --git a/src/platform/locales/text/zh.json b/src/platform/locales/text/zh.json index f07e17ca14..b2287ca707 100644 --- a/src/platform/locales/text/zh.json +++ b/src/platform/locales/text/zh.json @@ -2130,6 +2130,9 @@ "Group by Severity": "按严重性分组", "Groups": "组", "Gutter Icons": "装订区域图标", + "Gutter": "装订区域", + "Highlight modified lines in the gutter": "在装订区域中突出显示已修改的行", + "Highlight modified lines in error stripe on the scrollbar": "在滚动条的错误条纹中突出显示已修改的行", "HACK comment": "HACK 注释", "HEAD (Current Branch)": "HEAD(当前分支)", "HTML 5 file": "HTML 5 文件",