Skip to content

Commit a1413ea

Browse files
toggle formatting in diff view (#229)
1 parent c9e215e commit a1413ea

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
## [1.7.16] 2024-10-29
4+
5+
### Added
6+
7+
- toggle normalization in diff
8+
39
## [1.7.15] 2024-10-27
410

511
### Added

client/src/commands/registry.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export const AbapFsCommands = {
4545
openrevstate: "abapfs.openrevstate",
4646
opendiff: "abapfs.opendiff",
4747
opendiffNormalized: "abapfs.opendiffNormalized",
48+
togglediffNormalize: "abapfs.togglediffNormalize",
4849
changequickdiff: "abapfs.changequickdiff",
4950
remotediff: "abapfs.remotediff",
5051
comparediff: "abapfs.comparediff",

client/src/scm/abaprevisions/commands.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { command, AbapFsCommands } from "../../commands"
2-
import { Uri, QuickPickItem, window, commands, workspace, ProgressLocation } from "vscode"
2+
import { Uri, QuickPickItem, window, commands, workspace, ProgressLocation, TabInputTextDiff } from "vscode"
33
import { abapUri, uriRoot, getOrCreateRoot, getClient, ADTSCHEME, rootIsConnected } from "../../adt/conections"
44
import { AbapRevisionService, revLabel } from "./abaprevisionservice"
55
import { ADTClient, Revision } from "abap-adt-api"
@@ -8,7 +8,7 @@ import { revisionUri } from "./documentprovider"
88
import { RemoteManager, formatKey } from "../../config"
99
import { isAbapFile } from "abapfs"
1010
import { AGroup, AState } from "./abapscm"
11-
import { caughtToString } from "../../lib"
11+
import { caughtToString, atob, btoa } from "../../lib"
1212
import * as t from "io-ts"
1313
import { isRight } from "fp-ts/lib/Either"
1414
import { vsCodeUri } from "../../langClient"
@@ -291,6 +291,24 @@ export class AbapRevisionCommands {
291291
)
292292
}
293293

294+
@command(AbapFsCommands.togglediffNormalize)
295+
private static toggleDiffNormalize() {
296+
try {
297+
const tab = window.tabGroups.activeTabGroup.activeTab
298+
const toggleNorm = (u: Uri) => {
299+
const o = u.fragment ? JSON.parse(atob(u.fragment)) : {}
300+
o.normalized = !o.normalized
301+
return u.with({ fragment: btoa(JSON.stringify(o)) })
302+
}
303+
if (tab?.input instanceof TabInputTextDiff) {
304+
const { original, modified } = tab.input
305+
return commands.executeCommand<void>("vscode.diff", toggleNorm(original), toggleNorm(modified), tab.label)
306+
} else window.showInformationMessage("Unable to normalize this comparison")
307+
} catch (error) {
308+
window.showErrorMessage(caughtToString(error))
309+
}
310+
}
311+
294312
@command(AbapFsCommands.openrevstate)
295313
private static async openState(state: AState) {
296314
const document = await workspace.openTextDocument(state.resourceUri)

package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,11 @@
455455
"light": "client/images/light/icon-compare-formatted.svg"
456456
}
457457
},
458+
{
459+
"command": "abapfs.togglediffNormalize",
460+
"title": "Toggle code normalization",
461+
"icon": "$(law)"
462+
},
458463
{
459464
"command": "abapfs.transportObjectDiff",
460465
"title": "Diff with current version",
@@ -760,6 +765,10 @@
760765
"command": "abapfs.opendiffNormalized",
761766
"when": "hideCommands.never"
762767
},
768+
{
769+
"command": "abapfs.togglediffNormalize",
770+
"when": "hideCommands.never"
771+
},
763772
{
764773
"command": "abapfs.clearScmGroup",
765774
"when": "hideCommands.never"
@@ -1012,6 +1021,11 @@
10121021
"command": "abapfs.activate",
10131022
"group": "navigation",
10141023
"when": "resourceScheme == adt && editorLangId =~ /abap|cds|xml/ && abapfs:showActivate "
1024+
},
1025+
{
1026+
"command": "abapfs.togglediffNormalize",
1027+
"group": "navigation",
1028+
"when": "isInDiffEditor && editorLangId =~ /abap/"
10151029
}
10161030
],
10171031
"editor/title/run": [

0 commit comments

Comments
 (0)