Skip to content

Commit

Permalink
fix: consider font styles (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
moshfeu authored Apr 10, 2022
1 parent add096c commit 64af561
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "diff-merge",
"displayName": "Diff & Merge",
"description": "Show diffs and merge",
"version": "0.6.1",
"version": "0.7.0",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
16 changes: 9 additions & 7 deletions resources/monaco/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let diffActionsNode,

export function render(
_diffEditor,
{ rightPath, notSupportedFile, leftContent, rightContent, theme, tabSize }
{ rightPath, notSupportedFile, leftContent, rightContent, theme, styles: {tabSize, fontSize, fontFamily} }
) {
setTheme(theme);
diffEditor = _diffEditor;
Expand All @@ -33,16 +33,18 @@ export function render(
diffEditor.getModifiedEditor().onDidChangeModelContent(onDidUpdateDiff);
bindSaveShortcut();
extractEditorStyles(diffEditor);
setTabSize(tabSize);
setEditorStyles({tabSize, fontSize, fontFamily});
listenToDiffEditorResize(diffEditor.getModifiedEditor().getDomNode());
}

function setTabSize(tabSize) {
function setEditorStyles({tabSize, fontSize, fontFamily}) {
const { originalEditor, modifiedEditor } = diffEditor;
const updateTabSize = (model) =>
model.updateOptions({ tabSize, detectIndentation: false });
updateTabSize(originalEditor.getModel());
updateTabSize(modifiedEditor.getModel());
const updateTabSize = (editor) => {
editor.updateOptions({ fontSize, fontFamily});
editor.getModel().updateOptions({ tabSize, detectIndentation: false });
}
updateTabSize(originalEditor);
updateTabSize(modifiedEditor);
}

function setEditorValue(editor, value) {
Expand Down
2 changes: 1 addition & 1 deletion src/theme/extractor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { commands, window, Selection, Range, Position } from 'vscode';
import { commands, window, Range, Position } from 'vscode';
import { convertToMonacoTheme } from './adapter';
import { log } from '../logger';

Expand Down
6 changes: 5 additions & 1 deletion src/webview/extendedWebview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ export interface IExtendedWebviewEnvDiff {
rightContent: string;
fileNotSupported: string;
theme: any;
tabSize: number;
styles: {
tabSize: number;
fontFamily: string;
fontSize: number;
}
}

export type ExtendedWebviewEnv = IExtendedWebviewEnvContentOnly | IExtendedWebviewEnvDiff;
Expand Down
8 changes: 6 additions & 2 deletions src/webview/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function showDiff({ leftContent, rightContent, leftPath, rightPath,
);

const theme = await extract();
const { tabSize } = workspace.getConfiguration('editor');
const { tabSize, fontFamily, fontSize } = workspace.getConfiguration('editor');

const webviewEnv: ExtendedWebviewEnv = {
leftPath,
Expand All @@ -43,7 +43,11 @@ export async function showDiff({ leftContent, rightContent, leftPath, rightPath,
rightContent,
fileNotSupported,
theme,
tabSize
styles: {
tabSize,
fontFamily,
fontSize,
}
};

const extendsWebView = new ExtendedWebview(
Expand Down

0 comments on commit 64af561

Please sign in to comment.