1
0
mirror of https://github.com/desktop/desktop synced 2024-07-05 00:58:57 +00:00

Add diff check marks setting

This commit is contained in:
tidy-dev 2024-02-07 08:49:29 -05:00
parent 0780dfdad6
commit a1fc55bdf2
12 changed files with 56 additions and 3 deletions

View File

@ -332,6 +332,9 @@ export interface IAppState {
| PullRequestSuggestedNextAction
| undefined
/** Whether or not the user will see check marks indicating a line is included in the check in the diff */
readonly showDiffCheckMarks: boolean
/**
* Cached repo rulesets. Used to prevent repeatedly querying the same
* rulesets to check their bypass status.

View File

@ -407,6 +407,9 @@ const lastThankYouKey = 'version-and-users-of-last-thank-you'
const pullRequestSuggestedNextActionKey =
'pull-request-suggested-next-action-key'
const showDiffCheckMarksDefault = true
const showDiffCheckMarksKey = 'diff-check-marks-visible'
export class AppStore extends TypedBaseStore<IAppState> {
private readonly gitStoreCache: GitStoreCache
@ -537,6 +540,8 @@ export class AppStore extends TypedBaseStore<IAppState> {
| PullRequestSuggestedNextAction
| undefined = undefined
private showDiffCheckMarks: boolean = showDiffCheckMarksDefault
private cachedRepoRulesets = new Map<number, IAPIRepoRuleset>()
public constructor(
@ -1018,6 +1023,7 @@ export class AppStore extends TypedBaseStore<IAppState> {
pullRequestSuggestedNextAction: this.pullRequestSuggestedNextAction,
resizablePaneActive: this.resizablePaneActive,
cachedRepoRulesets: this.cachedRepoRulesets,
showDiffCheckMarks: this.showDiffCheckMarks,
}
}
@ -2206,6 +2212,11 @@ export class AppStore extends TypedBaseStore<IAppState> {
PullRequestSuggestedNextAction
) ?? defaultPullRequestSuggestedNextAction
this.showDiffCheckMarks = getBoolean(
showDiffCheckMarksKey,
showDiffCheckMarksDefault
)
this.emitUpdateNow()
this.accountsStore.refresh()

View File

@ -3288,6 +3288,7 @@ export class App extends React.Component<IAppProps, IAppState> {
imageDiffType={state.imageDiffType}
hideWhitespaceInChangesDiff={state.hideWhitespaceInChangesDiff}
hideWhitespaceInHistoryDiff={state.hideWhitespaceInHistoryDiff}
showDiffCheckMarks={state.showDiffCheckMarks}
showSideBySideDiff={state.showSideBySideDiff}
focusCommitMessage={state.focusCommitMessage}
askForConfirmationOnDiscardChanges={

View File

@ -49,6 +49,9 @@ interface IChangesProps {
*/
readonly showSideBySideDiff: boolean
/** Whether or not to show the diff check marks indicating inclusion in a commit */
readonly showDiffCheckMarks: boolean
/** Called when the user opens the diff options popover */
readonly onDiffOptionsOpened: () => void
}
@ -120,6 +123,7 @@ export class Changes extends React.Component<IChangesProps, {}> {
diff={this.props.diff}
hideWhitespaceInDiff={this.props.hideWhitespaceInDiff}
showSideBySideDiff={this.props.showSideBySideDiff}
showDiffCheckMarks={this.props.showDiffCheckMarks}
askForConfirmationOnDiscardChanges={
this.props.askForConfirmationOnDiscardChanges
}

View File

@ -76,6 +76,9 @@ interface IDiffProps {
/** Whether we should show a confirmation dialog when the user discards changes */
readonly askForConfirmationOnDiscardChanges?: boolean
/** Whether or not to show the diff check marks indicating inclusion in a commit */
readonly showDiffCheckMarks: boolean
/**
* Called when the user requests to open a binary file in an the
* system-assigned application for said file type.
@ -287,6 +290,7 @@ export class Diff extends React.Component<IDiffProps, IDiffState> {
onHideWhitespaceInDiffChanged={
this.props.onHideWhitespaceInDiffChanged
}
showDiffCheckMarks={this.props.showDiffCheckMarks}
/>
)
}

View File

@ -68,6 +68,11 @@ interface ISeamlessDiffSwitcherProps {
// eslint-disable-next-line react/no-unused-prop-types
readonly showSideBySideDiff: boolean
/** Whether or not to show the diff check marks indicating inclusion in a commit */
// Used in getDerivedStateFromProps, no-unused-prop-types doesn't know that
// eslint-disable-next-line react/no-unused-prop-types
readonly showDiffCheckMarks: boolean
/** Whether we should show a confirmation dialog when the user discards changes */
readonly askForConfirmationOnDiscardChanges?: boolean
@ -327,6 +332,7 @@ export class SeamlessDiffSwitcher extends React.Component<
readOnly,
hideWhitespaceInDiff,
showSideBySideDiff,
showDiffCheckMarks,
onIncludeChanged,
onDiscardChanges,
file,
@ -363,6 +369,7 @@ export class SeamlessDiffSwitcher extends React.Component<
askForConfirmationOnDiscardChanges={
this.props.askForConfirmationOnDiscardChanges
}
showDiffCheckMarks={showDiffCheckMarks}
onIncludeChanged={isLoadingDiff ? noop : onIncludeChanged}
onDiscardChanges={isLoadingDiff ? noop : onDiscardChanges}
onOpenBinaryFile={isLoadingDiff ? noop : onOpenBinaryFile}

View File

@ -151,6 +151,9 @@ interface ISideBySideDiffRowProps {
expansionType: DiffHunkExpansionType,
element: HTMLButtonElement | null
) => void
/** Whether or not to show the diff check marks indicating inclusion in a commit */
readonly showDiffCheckMarks: boolean
}
interface ISideBySideDiffRowState {
@ -400,10 +403,17 @@ export class SideBySideDiffRow extends React.Component<
* for side-by-side diffs the gutter contains the line number of only one side.
*/
private get lineGutterWidth() {
const { showSideBySideDiff, lineNumberWidth, isDiffSelectable } = this.props
const {
showSideBySideDiff,
lineNumberWidth,
isDiffSelectable,
showDiffCheckMarks,
} = this.props
return (
(showSideBySideDiff ? lineNumberWidth : lineNumberWidth * 2) +
(isDiffSelectable && enableDiffCheckMarks() ? 14 : 0)
(isDiffSelectable && showDiffCheckMarks && enableDiffCheckMarks()
? 14
: 0)
)
}
@ -546,7 +556,11 @@ export class SideBySideDiffRow extends React.Component<
}
private renderLineNumberCheck(isSelected?: boolean) {
if (!this.props.isDiffSelectable || !enableDiffCheckMarks()) {
if (
!this.props.isDiffSelectable ||
!enableDiffCheckMarks() ||
!this.props.showDiffCheckMarks
) {
return null
}

View File

@ -135,6 +135,9 @@ interface ISideBySideDiffProps {
*/
readonly showSideBySideDiff: boolean
/** Whether or not to show the diff check marks indicating inclusion in a commit */
readonly showDiffCheckMarks: boolean
/** Called when the user changes the hide whitespace in diffs setting. */
readonly onHideWhitespaceInDiffChanged: (checked: boolean) => void
}
@ -661,6 +664,7 @@ export class SideBySideDiff extends React.Component<
isHunkHovered={isHunkHovered}
showSideBySideDiff={this.props.showSideBySideDiff}
hideWhitespaceInDiff={this.props.hideWhitespaceInDiff}
showDiffCheckMarks={this.props.showDiffCheckMarks}
onStartSelection={this.onStartSelection}
onMouseEnterHunk={this.onMouseEnterHunk}
onMouseLeaveHunk={this.onMouseLeaveHunk}

View File

@ -173,6 +173,7 @@ export class SelectedCommits extends React.Component<
diff={diff}
readOnly={true}
hideWhitespaceInDiff={this.props.hideWhitespaceInDiff}
showDiffCheckMarks={false}
showSideBySideDiff={this.props.showSideBySideDiff}
onOpenBinaryFile={this.props.onOpenBinaryFile}
onChangeImageDiffType={this.props.onChangeImageDiffType}

View File

@ -301,6 +301,7 @@ export class PullRequestFilesChanged extends React.Component<
readOnly={true}
hideWhitespaceInDiff={hideWhitespaceInDiff}
showSideBySideDiff={showSideBySideDiff}
showDiffCheckMarks={false}
onOpenBinaryFile={this.onOpenBinaryFile}
onChangeImageDiffType={this.onChangeImageDiffType}
onHideWhitespaceInDiffChanged={this.onHideWhitespaceInDiffChanged}

View File

@ -49,6 +49,7 @@ interface IRepositoryViewProps {
readonly hideWhitespaceInChangesDiff: boolean
readonly hideWhitespaceInHistoryDiff: boolean
readonly showSideBySideDiff: boolean
readonly showDiffCheckMarks: boolean
readonly askForConfirmationOnDiscardChanges: boolean
readonly askForConfirmationOnDiscardStash: boolean
readonly askForConfirmationOnCheckoutCommit: boolean
@ -533,6 +534,7 @@ export class RepositoryView extends React.Component<
imageDiffType={this.props.imageDiffType}
hideWhitespaceInDiff={this.props.hideWhitespaceInChangesDiff}
showSideBySideDiff={this.props.showSideBySideDiff}
showDiffCheckMarks={this.props.showDiffCheckMarks}
onOpenBinaryFile={this.onOpenBinaryFile}
onOpenSubmodule={this.onOpenSubmodule}
onChangeImageDiffType={this.onChangeImageDiffType}

View File

@ -109,6 +109,7 @@ export class StashDiffViewer extends React.PureComponent<IStashDiffViewerProps>
diff={stashedFileDiff}
imageDiffType={imageDiffType}
hideWhitespaceInDiff={false}
showDiffCheckMarks={false}
showSideBySideDiff={this.props.showSideBySideDiff}
onOpenBinaryFile={onOpenBinaryFile}
onChangeImageDiffType={onChangeImageDiffType}