diff --git a/client/web/src/repo/blob/CodeMirrorBlob.tsx b/client/web/src/repo/blob/CodeMirrorBlob.tsx index 021523669cbf..c80975a8c86f 100644 --- a/client/web/src/repo/blob/CodeMirrorBlob.tsx +++ b/client/web/src/repo/blob/CodeMirrorBlob.tsx @@ -151,8 +151,12 @@ const staticExtensions: Extension = [ backgroundColor: 'var(--code-bg)', borderRight: 'initial', }, + '.cm-content:focus-visible': { + outline: 'none', + boxShadow: 'none', + }, '.cm-line': { - paddingLeft: '1rem', + paddingLeft: '0', }, '.selected-line': { backgroundColor: 'var(--code-selection-bg)', @@ -278,6 +282,7 @@ export const Blob: React.FunctionComponent = props => { navigateToLineOnAnyClick: navigateToLineOnAnyClick ?? false, enableSelectionDrivenCodeNavigation, }), + codeFoldingExtension(), enableSelectionDrivenCodeNavigation ? tokenSelectionExtension() : [], enableLinkDrivenCodeNavigation ? tokensAsLinks({ navigate: navigateRef.current, blobInfo, preloadGoToDefinition }) @@ -304,7 +309,6 @@ export const Blob: React.FunctionComponent = props => { overrideBrowserFindInPageShortcut: useFileSearch, onOverrideBrowserFindInPageToggle: setUseFileSearch, }), - codeFoldingExtension(), ], // A couple of values are not dependencies (blameDecorations, blobProps, // hasPin, position and settings) because those are updated in effects diff --git a/client/web/src/repo/blob/LegacyBlob.module.scss b/client/web/src/repo/blob/LegacyBlob.module.scss index 602ba38e5537..98c82b368dc1 100644 --- a/client/web/src/repo/blob/LegacyBlob.module.scss +++ b/client/web/src/repo/blob/LegacyBlob.module.scss @@ -107,6 +107,6 @@ background-color: var(--body-bg); } -:global(.cm-editor:not(:focus-within) .focus-visible) { +:global(.cm-editor:not(:focus-within) :focus-visible) { box-shadow: none; } diff --git a/client/web/src/repo/blob/codemirror/blame-decorations.tsx b/client/web/src/repo/blob/codemirror/blame-decorations.tsx index 92524d382b88..d2e1e817eaaf 100644 --- a/client/web/src/repo/blob/codemirror/blame-decorations.tsx +++ b/client/web/src/repo/blob/codemirror/blame-decorations.tsx @@ -220,9 +220,7 @@ const showGitBlameDecorations = Facet.define({ return RectangleMarker.forRange( view, - 'selected-line', + classNames('selected-line', { ['blame-visible']: view.state.facet(blobPropsFacet).isBlameVisible }), EditorSelection.range(startLine.from, Math.min(endLine.to + 1, view.state.doc.length)) ) }, @@ -132,13 +136,28 @@ export const selectedLines = StateField.define({ class: 'selected-lines-layer', }), EditorView.theme({ + /** + * [RectangleMarker.forRange](https://sourcegraph.com/github.com/codemirror/view@a0a0b9ef5a4deaf58842422ac080030042d83065/-/blob/src/layer.ts?L60-75) + * returns absolutely positioned markers. Markers top position has extra 1px (6px in case blame decorations + * are visible) more in its `top` value breaking alignment wih the line. + * We compensate this spacing by setting negative margin-top. + */ '.selected-lines-layer .selected-line': { - /** - * [RectangleMarker.forRange](https://sourcegraph.com/github.com/codemirror/view@a0a0b9ef5a4deaf58842422ac080030042d83065/-/blob/src/layer.ts?L60-75) - * returns absolutely positioned markers. Markers top position has extra 1px more in its `top` value breaking alignment wih the line. - * We compensate this spacing by setting negative margin-top. - */ marginTop: '-1px', + + // Ensure selection marker height matches line height. + minHeight: '1rem', + }, + '.selected-lines-layer .selected-line.blame-visible': { + marginTop: '-6px', + + // Ensure selection marker height matches the increased line height. + minHeight: 'calc(1.5rem + 1px)', + }, + + // Selected line background is set by adding 'selected-line' class to the layer markers. + '.cm-line.selected-line': { + background: 'transparent', }, /** @@ -148,9 +167,6 @@ export const selectedLines = StateField.define({ * highlight (background color) between the selected line gutters (decorated with {@link selectedLineGutterMarker}) and layer. * To remove this gap we move padding from `.cm-line` to the last gutter. */ - '.cm-line': { - paddingLeft: '0 !important', - }, '.cm-gutter:last-child .cm-gutterElement': { paddingRight: '1rem', }, diff --git a/client/web/src/repo/blob/codemirror/token-selection/keybindings.ts b/client/web/src/repo/blob/codemirror/token-selection/keybindings.ts index 95e6873b92f5..d62aa119378f 100644 --- a/client/web/src/repo/blob/codemirror/token-selection/keybindings.ts +++ b/client/web/src/repo/blob/codemirror/token-selection/keybindings.ts @@ -277,13 +277,6 @@ function textSelectionExtension(): Extension { }, '.cm-selectionLayer .cm-selectionBackground': { background: 'var(--code-selection-bg-2)', - - /** - * [RectangleMarker.forRange](https://sourcegraph.com/github.com/codemirror/view@a0a0b9ef5a4deaf58842422ac080030042d83065/-/blob/src/layer.ts?L60-75) - * returns absolutely positioned markers. Markers top position has extra 1px more in its `top` value breaking alignment wih the line. - * We compensate this spacing by setting negative margin-top. - */ - marginTop: '-1px', }, }), ]