Merge pull request #11926 from say25/Decouple-Whitespace-Settings

Split Whitespace Settings
This commit is contained in:
Sergio Padrino 2021-04-06 18:53:58 +02:00 committed by GitHub
commit d449d4ff16
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 70 additions and 39 deletions

View file

@ -202,8 +202,11 @@ export interface IAppState {
/** What type of visual diff mode we should use to compare images */
readonly imageDiffType: ImageDiffType
/** Whether we should hide white space changes in diff */
readonly hideWhitespaceInDiff: boolean
/** Whether we should hide white space changes in changes diff */
readonly hideWhitespaceInChangesDiff: boolean
/** Whether we should hide white space changes in history diff */
readonly hideWhitespaceInHistoryDiff: boolean
/** Whether we should show side by side diffs */
readonly showSideBySideDiff: boolean

View file

@ -49,7 +49,7 @@ export function enableWSLDetection(): boolean {
/** Should the app show hide whitespace in changes tab */
export function enableHideWhitespaceInDiffOption(): boolean {
return enableDevelopmentFeatures()
return enableBetaFeatures()
}
/** Should the app use the shiny new TCP-based trampoline? */

View file

@ -317,8 +317,10 @@ const externalEditorKey: string = 'externalEditor'
const imageDiffTypeDefault = ImageDiffType.TwoUp
const imageDiffTypeKey = 'image-diff-type'
const hideWhitespaceInDiffDefault = false
const hideWhitespaceInDiffKey = 'hide-whitespace-in-diff'
const hideWhitespaceInChangesDiffDefault = false
const hideWhitespaceInChangesDiffKey = 'hide-whitespace-in-changes-diff'
const hideWhitespaceInHistoryDiffDefault = false
const hideWhitespaceInHistoryDiffKey = 'hide-whitespace-in-diff'
const commitSpellcheckEnabledDefault = true
const commitSpellcheckEnabledKey = 'commit-spellcheck-enabled'
@ -403,7 +405,8 @@ export class AppStore extends TypedBaseStore<IAppState> {
private confirmDiscardChanges: boolean = confirmDiscardChangesDefault
private askForConfirmationOnForcePush = askForConfirmationOnForcePushDefault
private imageDiffType: ImageDiffType = imageDiffTypeDefault
private hideWhitespaceInDiff: boolean = hideWhitespaceInDiffDefault
private hideWhitespaceInChangesDiff: boolean = hideWhitespaceInChangesDiffDefault
private hideWhitespaceInHistoryDiff: boolean = hideWhitespaceInHistoryDiffDefault
/** Whether or not the spellchecker is enabled for commit summary and description */
private commitSpellcheckEnabled: boolean = commitSpellcheckEnabledDefault
private showSideBySideDiff: boolean = ShowSideBySideDiffDefault
@ -780,7 +783,8 @@ export class AppStore extends TypedBaseStore<IAppState> {
uncommittedChangesStrategy: this.uncommittedChangesStrategy,
selectedExternalEditor: this.selectedExternalEditor,
imageDiffType: this.imageDiffType,
hideWhitespaceInDiff: this.hideWhitespaceInDiff,
hideWhitespaceInChangesDiff: this.hideWhitespaceInChangesDiff,
hideWhitespaceInHistoryDiff: this.hideWhitespaceInHistoryDiff,
showSideBySideDiff: this.showSideBySideDiff,
selectedShell: this.selectedShell,
repositoryFilterText: this.repositoryFilterText,
@ -1357,7 +1361,7 @@ export class AppStore extends TypedBaseStore<IAppState> {
repository,
file,
shas[0],
this.hideWhitespaceInDiff
this.hideWhitespaceInHistoryDiff
)
const stateAfterLoad = this.repositoryStateCache.get(repository)
@ -1729,7 +1733,14 @@ export class AppStore extends TypedBaseStore<IAppState> {
? imageDiffTypeDefault
: parseInt(imageDiffTypeValue)
this.hideWhitespaceInDiff = getBoolean(hideWhitespaceInDiffKey, false)
this.hideWhitespaceInChangesDiff = getBoolean(
hideWhitespaceInChangesDiffKey,
false
)
this.hideWhitespaceInHistoryDiff = getBoolean(
hideWhitespaceInHistoryDiffKey,
false
)
this.commitSpellcheckEnabled = getBoolean(
commitSpellcheckEnabledKey,
commitSpellcheckEnabledDefault
@ -2199,7 +2210,7 @@ export class AppStore extends TypedBaseStore<IAppState> {
const diff = await getWorkingDirectoryDiff(
repository,
selectedFileBeforeLoad,
enableHideWhitespaceInDiffOption() && this.hideWhitespaceInDiff
enableHideWhitespaceInDiffOption() && this.hideWhitespaceInChangesDiff
)
const stateAfterLoad = this.repositoryStateCache.get(repository)
@ -4653,20 +4664,26 @@ export class AppStore extends TypedBaseStore<IAppState> {
return Promise.resolve()
}
public async _setHideWhitespaceInDiff(
public _setHideWhitespaceInChangesDiff(
hideWhitespaceInDiff: boolean,
repository: Repository
): Promise<void> {
setBoolean(hideWhitespaceInChangesDiffKey, hideWhitespaceInDiff)
this.hideWhitespaceInChangesDiff = hideWhitespaceInDiff
return this.refreshChangesSection(repository, {
includingStatus: true,
clearPartialState: true,
})
}
public _setHideWhitespaceInHistoryDiff(
hideWhitespaceInDiff: boolean,
repository: Repository,
file: CommittedFileChange | null
): Promise<void> {
setBoolean(hideWhitespaceInDiffKey, hideWhitespaceInDiff)
this.hideWhitespaceInDiff = hideWhitespaceInDiff
if (enableHideWhitespaceInDiffOption()) {
await this.refreshChangesSection(repository, {
includingStatus: true,
clearPartialState: true,
})
}
setBoolean(hideWhitespaceInHistoryDiffKey, hideWhitespaceInDiff)
this.hideWhitespaceInHistoryDiff = hideWhitespaceInDiff
if (file === null) {
return this.updateChangesWorkingDirectoryDiff(repository)

View file

@ -2663,7 +2663,8 @@ export class App extends React.Component<IAppProps, IAppState> {
gitHubUserStore={this.props.gitHubUserStore}
onViewCommitOnGitHub={this.onViewCommitOnGitHub}
imageDiffType={state.imageDiffType}
hideWhitespaceInDiff={state.hideWhitespaceInDiff}
hideWhitespaceInChangesDiff={state.hideWhitespaceInChangesDiff}
hideWhitespaceInHistoryDiff={state.hideWhitespaceInHistoryDiff}
showSideBySideDiff={state.showSideBySideDiff}
focusCommitMessage={state.focusCommitMessage}
askForConfirmationOnDiscardChanges={

View file

@ -127,10 +127,8 @@ export class Changes extends React.Component<IChangesProps, {}> {
this.props.dispatcher.onShowSideBySideDiffChanged(showSideBySideDiff)
}
private onHideWhitespaceInDiffChanged = async (
hideWhitespaceInDiff: boolean
) => {
await this.props.dispatcher.onHideWhitespaceInDiffChanged(
private onHideWhitespaceInDiffChanged = (hideWhitespaceInDiff: boolean) => {
return this.props.dispatcher.onHideWhitespaceInChangesDiffChanged(
hideWhitespaceInDiff,
this.props.repository
)

View file

@ -74,10 +74,12 @@ export class DiffOptions extends React.Component<
})
}
private onHideWhitespaceChangesChanged = async (
private onHideWhitespaceChangesChanged = (
event: React.FormEvent<HTMLInputElement>
) => {
await this.props.onHideWhitespaceChangesChanged(event.currentTarget.checked)
return this.props.onHideWhitespaceChangesChanged(
event.currentTarget.checked
)
}
public render() {

View file

@ -1941,13 +1941,24 @@ export class Dispatcher {
return this.appStore._changeImageDiffType(type)
}
/** Change the hide whitespace in diff setting */
public onHideWhitespaceInDiffChanged(
/** Change the hide whitespace in changes diff setting */
public onHideWhitespaceInChangesDiffChanged(
hideWhitespaceInDiff: boolean,
repository: Repository
): Promise<void> {
return this.appStore._setHideWhitespaceInChangesDiff(
hideWhitespaceInDiff,
repository
)
}
/** Change the hide whitespace in history diff setting */
public onHideWhitespaceInHistoryDiffChanged(
hideWhitespaceInDiff: boolean,
repository: Repository,
file: CommittedFileChange | null = null
): Promise<void> {
return this.appStore._setHideWhitespaceInDiff(
return this.appStore._setHideWhitespaceInHistoryDiff(
hideWhitespaceInDiff,
repository,
file

View file

@ -157,11 +157,11 @@ export class CommitSummary extends React.Component<
}
}
private onHideWhitespaceInDiffChanged = async (
private onHideWhitespaceInDiffChanged = (
event: React.FormEvent<HTMLInputElement>
) => {
const value = event.currentTarget.checked
await this.props.onHideWhitespaceInDiffChanged(value)
return this.props.onHideWhitespaceInDiffChanged(value)
}
private onResized = () => {

View file

@ -190,10 +190,8 @@ export class SelectedCommit extends React.Component<
}
}
private onHideWhitespaceInDiffChanged = async (
hideWhitespaceInDiff: boolean
) => {
await this.props.dispatcher.onHideWhitespaceInDiffChanged(
private onHideWhitespaceInDiffChanged = (hideWhitespaceInDiff: boolean) => {
return this.props.dispatcher.onHideWhitespaceInHistoryDiffChanged(
hideWhitespaceInDiff,
this.props.repository,
this.props.selectedFile as CommittedFileChange

View file

@ -46,7 +46,8 @@ interface IRepositoryViewProps {
readonly gitHubUserStore: GitHubUserStore
readonly onViewCommitOnGitHub: (SHA: string) => void
readonly imageDiffType: ImageDiffType
readonly hideWhitespaceInDiff: boolean
readonly hideWhitespaceInChangesDiff: boolean
readonly hideWhitespaceInHistoryDiff: boolean
readonly showSideBySideDiff: boolean
readonly askForConfirmationOnDiscardChanges: boolean
readonly focusCommitMessage: boolean
@ -371,7 +372,7 @@ export class RepositoryView extends React.Component<
selectedDiffType={this.props.imageDiffType}
externalEditorLabel={this.props.externalEditorLabel}
onOpenInExternalEditor={this.props.onOpenInExternalEditor}
hideWhitespaceInDiff={this.props.hideWhitespaceInDiff}
hideWhitespaceInDiff={this.props.hideWhitespaceInHistoryDiff}
showSideBySideDiff={this.props.showSideBySideDiff}
onOpenBinaryFile={this.onOpenBinaryFile}
onChangeImageDiffType={this.onChangeImageDiffType}
@ -449,7 +450,7 @@ export class RepositoryView extends React.Component<
diff={diff}
isCommitting={this.props.state.isCommitting}
imageDiffType={this.props.imageDiffType}
hideWhitespaceInDiff={this.props.hideWhitespaceInDiff}
hideWhitespaceInDiff={this.props.hideWhitespaceInChangesDiff}
showSideBySideDiff={this.props.showSideBySideDiff}
onOpenBinaryFile={this.onOpenBinaryFile}
onChangeImageDiffType={this.onChangeImageDiffType}