mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 23:15:43 +01:00
New diff view props for controlling hunk/line interaction (#2047)
Move hunk styling from review plugin to core and make reusable
This commit is contained in:
committed by
GitHub
parent
9ae22c1cf2
commit
5f9db5cf4d
2
gradle/changelog/hunk_hover_icon.yaml
Normal file
2
gradle/changelog/hunk_hover_icon.yaml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
- type: added
|
||||||
|
description: New diff view props for controlling hunk/line interaction ([#2047](https://github.com/scm-manager/scm-manager/pull/2047))
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -141,6 +141,14 @@ storiesOf("Repositories/Diff", module)
|
|||||||
const hunkDiffFiles = parser.parse(hunksDiff);
|
const hunkDiffFiles = parser.parse(hunksDiff);
|
||||||
return <Diff diff={hunkDiffFiles} />;
|
return <Diff diff={hunkDiffFiles} />;
|
||||||
})
|
})
|
||||||
|
.add("Hunk gutter hover icon", () => {
|
||||||
|
const hunkDiffFiles = parser.parse(hunksDiff);
|
||||||
|
return <Diff diff={hunkDiffFiles} hunkGutterHoverIcon="\f075" />;
|
||||||
|
})
|
||||||
|
.add("Highlight line on hover", () => {
|
||||||
|
const hunkDiffFiles = parser.parse(hunksDiff);
|
||||||
|
return <Diff diff={hunkDiffFiles} highlightLineOnHover />;
|
||||||
|
})
|
||||||
.add("Binaries", () => {
|
.add("Binaries", () => {
|
||||||
const binaryDiffFiles = parser.parse(binaryDiff);
|
const binaryDiffFiles = parser.parse(binaryDiff);
|
||||||
return <Diff diff={binaryDiffFiles} />;
|
return <Diff diff={binaryDiffFiles} />;
|
||||||
|
|||||||
@@ -64,4 +64,13 @@ export type DiffObjectProps = {
|
|||||||
isCollapsed?: (file: File) => boolean;
|
isCollapsed?: (file: File) => boolean;
|
||||||
onCollapseStateChange?: (file: File, newState?: boolean) => void;
|
onCollapseStateChange?: (file: File, newState?: boolean) => void;
|
||||||
hunkClass?: (hunk: Hunk) => string;
|
hunkClass?: (hunk: Hunk) => string;
|
||||||
|
/**
|
||||||
|
* Fontawesome Icon Unicode
|
||||||
|
*
|
||||||
|
* @see https://fontawesome.com/icons
|
||||||
|
* @example
|
||||||
|
* "\f075"
|
||||||
|
*/
|
||||||
|
hunkGutterHoverIcon?: string;
|
||||||
|
highlightLineOnHover?: boolean;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -61,6 +61,33 @@ type State = Collapsible & {
|
|||||||
expansionError?: any;
|
expansionError?: any;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const StyledHunk = styled(Hunk)`${props => {
|
||||||
|
let style = props.icon ? `
|
||||||
|
.diff-gutter:hover::after {
|
||||||
|
font-size: inherit;
|
||||||
|
margin-left: 0.5em;
|
||||||
|
font-family: "Font Awesome 5 Free";
|
||||||
|
content: "${props.icon}";
|
||||||
|
color: var(--scm-column-selection);
|
||||||
|
}
|
||||||
|
` : "";
|
||||||
|
if (!props.actionable) {
|
||||||
|
style += `
|
||||||
|
.diff-gutter {
|
||||||
|
cursor: default;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
if (props.highlightLineOnHover) {
|
||||||
|
style += `
|
||||||
|
tr.diff-line:hover > td {
|
||||||
|
background-color: var(--sh-selected-color);
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
return style;
|
||||||
|
}}`;
|
||||||
|
|
||||||
const DiffFilePanel = styled.div`
|
const DiffFilePanel = styled.div`
|
||||||
/* remove bottom border for collapsed panels */
|
/* remove bottom border for collapsed panels */
|
||||||
${(props: Collapsible) => (props.collapsed ? "border-bottom: none;" : "")};
|
${(props: Collapsible) => (props.collapsed ? "border-bottom: none;" : "")};
|
||||||
@@ -315,13 +342,18 @@ class DiffFile extends React.Component<Props, State> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const gutterEvents = this.createGutterEvents(hunk);
|
||||||
|
|
||||||
items.push(
|
items.push(
|
||||||
<Hunk
|
<StyledHunk
|
||||||
key={"hunk-" + hunk.content}
|
key={"hunk-" + hunk.content}
|
||||||
hunk={expandableHunk.hunk}
|
hunk={expandableHunk.hunk}
|
||||||
widgets={this.collectHunkAnnotations(hunk)}
|
widgets={this.collectHunkAnnotations(hunk)}
|
||||||
gutterEvents={this.createGutterEvents(hunk)}
|
gutterEvents={gutterEvents}
|
||||||
className={this.props.hunkClass ? this.props.hunkClass(hunk) : null}
|
className={this.props.hunkClass ? this.props.hunkClass(hunk) : null}
|
||||||
|
icon={this.props.hunkGutterHoverIcon}
|
||||||
|
actionable={!!gutterEvents}
|
||||||
|
highlightLineOnHover={this.props.highlightLineOnHover}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
if (file._links?.lines) {
|
if (file._links?.lines) {
|
||||||
|
|||||||
Reference in New Issue
Block a user