Improve Changes diff experience
This commit is contained in:
@@ -1,9 +1,21 @@
|
||||
import { parseDiffFromFile, parsePatchFiles, type FileDiffMetadata } from '@pierre/diffs';
|
||||
import {
|
||||
parseDiffFromFile,
|
||||
parsePatchFiles,
|
||||
processFile,
|
||||
trimPatchContext,
|
||||
type FileDiffMetadata,
|
||||
} from '@pierre/diffs';
|
||||
|
||||
const PATCH_DIFF_CACHE_LIMIT = 64;
|
||||
const DEFAULT_PATCH_CONTEXT_LINES = 3;
|
||||
const patchFileDiffCache = new Map<string, FileDiffMetadata>();
|
||||
|
||||
export const fileDiffFromContent = (file: string, before: string, after: string): FileDiffMetadata => {
|
||||
export const fileDiffFromContent = (
|
||||
file: string,
|
||||
before: string,
|
||||
after: string,
|
||||
contextLines = DEFAULT_PATCH_CONTEXT_LINES
|
||||
): FileDiffMetadata => {
|
||||
if (!before && !after) {
|
||||
return emptyFileDiff(file);
|
||||
}
|
||||
@@ -11,11 +23,16 @@ export const fileDiffFromContent = (file: string, before: string, after: string)
|
||||
return parseDiffFromFile(
|
||||
{ name: file, contents: before },
|
||||
{ name: file, contents: after },
|
||||
{ context: contextLines },
|
||||
);
|
||||
};
|
||||
|
||||
export const fileDiffFromPatch = (file: string, patch: string): FileDiffMetadata => {
|
||||
const key = `${file}\0${patch}`;
|
||||
export const fileDiffFromPatch = (
|
||||
file: string,
|
||||
patch: string,
|
||||
contextLines = DEFAULT_PATCH_CONTEXT_LINES
|
||||
): FileDiffMetadata => {
|
||||
const key = `${file}\0${contextLines}\0${patch}`;
|
||||
const cached = patchFileDiffCache.get(key);
|
||||
if (cached) {
|
||||
patchFileDiffCache.delete(key);
|
||||
@@ -25,7 +42,10 @@ export const fileDiffFromPatch = (file: string, patch: string): FileDiffMetadata
|
||||
|
||||
const completeContents = completePatchContents(patch);
|
||||
const value = completeContents
|
||||
? fileDiffFromContent(file, completeContents.before, completeContents.after)
|
||||
? (processFile(trimPatchContext(patch, contextLines), {
|
||||
oldFile: { name: file, contents: completeContents.before },
|
||||
newFile: { name: file, contents: completeContents.after },
|
||||
}) ?? emptyFileDiff(file))
|
||||
: (parsePatchFiles(withPatchHeader(file, patch))[0]?.files[0] ?? emptyFileDiff(file));
|
||||
patchFileDiffCache.set(key, value);
|
||||
|
||||
|
||||
@@ -1209,6 +1209,8 @@ export const dict = {
|
||||
'diffView.actions.renderAnyway': 'Render anyway',
|
||||
'diffView.actions.expandAll': 'Expand all',
|
||||
'diffView.actions.collapseAll': 'Collapse all',
|
||||
'diffView.actions.loadFullFiles': 'Load full files',
|
||||
'diffView.actions.disableFullFiles': 'Unload full files',
|
||||
'diffView.actions.disableLineWrap': 'Disable line wrap',
|
||||
'diffView.actions.enableLineWrap': 'Enable line wrap',
|
||||
'diffView.actions.openFileInEditorAtChange': 'Open this file in editor at change',
|
||||
|
||||
@@ -1175,6 +1175,8 @@ export const dict: Record<I18nKey, string> = {
|
||||
"diffView.actions.renderAnyway": "Renderizar de todos modos",
|
||||
"diffView.actions.expandAll": "Expandir todo",
|
||||
"diffView.actions.collapseAll": "Contraer todo",
|
||||
"diffView.actions.loadFullFiles": "Cargar archivos completos",
|
||||
"diffView.actions.disableFullFiles": "No cargar archivos completos",
|
||||
"diffView.actions.disableLineWrap": "Desactivar ajuste de línea",
|
||||
"diffView.actions.enableLineWrap": "Activar ajuste de línea",
|
||||
"diffView.actions.openFileInEditorAtChange": "Abrir este archivo en el editor en el cambio",
|
||||
|
||||
@@ -1082,6 +1082,8 @@ export const dict = {
|
||||
'diffView.actions.renderAnyway': 'Afficher quand même',
|
||||
'diffView.actions.expandAll': 'Tout développer',
|
||||
'diffView.actions.collapseAll': 'Tout réduire',
|
||||
'diffView.actions.loadFullFiles': 'Charger les fichiers complets',
|
||||
'diffView.actions.disableFullFiles': 'Ne plus charger les fichiers complets',
|
||||
'diffView.actions.disableLineWrap': 'Désactiver le retour à la ligne',
|
||||
'diffView.actions.enableLineWrap': 'Activer le retour à la ligne',
|
||||
'diffView.actions.openFileInEditorAtChange': 'Ouvrez ce fichier dans l\'éditeur lors du changement',
|
||||
|
||||
@@ -1212,6 +1212,8 @@ export const dict: Record<I18nKey, string> = {
|
||||
'diffView.actions.renderAnyway': '그래도 렌더링',
|
||||
'diffView.actions.expandAll': '모두 펼치기',
|
||||
'diffView.actions.collapseAll': '모두 접기',
|
||||
'diffView.actions.loadFullFiles': '전체 파일 불러오기',
|
||||
'diffView.actions.disableFullFiles': '전체 파일 불러오기 끄기',
|
||||
'diffView.actions.disableLineWrap': '줄 바꿈 끄기',
|
||||
'diffView.actions.enableLineWrap': '줄 바꿈 켜기',
|
||||
'diffView.actions.openFileInEditorAtChange': '변경 위치에서 이 파일을 에디터로 열기',
|
||||
|
||||
@@ -1412,6 +1412,8 @@ export const dict: Record<I18nKey, string> = {
|
||||
'diffView.actions.enableLineWrap': 'Włącz zawijanie linii',
|
||||
'diffView.actions.expandAll': 'Rozwiń wszystko',
|
||||
'diffView.actions.collapseAll': 'Zwiń wszystko',
|
||||
'diffView.actions.loadFullFiles': 'Wczytaj pełne pliki',
|
||||
'diffView.actions.disableFullFiles': 'Nie wczytuj pełnych plików',
|
||||
'diffView.actions.openFileAtFirstChangedLine': 'Otwórz plik na pierwszej zmienionej linii',
|
||||
'diffView.actions.openFileInEditorAtChange': 'Otwórz plik w edytorze na zmianie',
|
||||
'diffView.actions.renderAnyway': 'Renderuj mimo to',
|
||||
|
||||
@@ -1175,6 +1175,8 @@ export const dict: Record<I18nKey, string> = {
|
||||
"diffView.actions.renderAnyway": "Renderizar mesmo assim",
|
||||
"diffView.actions.expandAll": "Expandir tudo",
|
||||
"diffView.actions.collapseAll": "Recolher tudo",
|
||||
"diffView.actions.loadFullFiles": "Carregar arquivos completos",
|
||||
"diffView.actions.disableFullFiles": "Não carregar arquivos completos",
|
||||
"diffView.actions.disableLineWrap": "Desativar ajuste de linha",
|
||||
"diffView.actions.enableLineWrap": "Ativar ajuste de linha",
|
||||
"diffView.actions.openFileInEditorAtChange": "Abrir este arquivo no editor nesta alteração",
|
||||
|
||||
@@ -1175,6 +1175,8 @@ export const dict: Record<I18nKey, string> = {
|
||||
"diffView.actions.renderAnyway": "Все одно відрендерити",
|
||||
"diffView.actions.expandAll": "Розгорнути все",
|
||||
"diffView.actions.collapseAll": "Згорнути все",
|
||||
"diffView.actions.loadFullFiles": "Завантажити повні файли",
|
||||
"diffView.actions.disableFullFiles": "Не завантажувати повні файли",
|
||||
"diffView.actions.disableLineWrap": "Вимкнути перенос рядків",
|
||||
"diffView.actions.enableLineWrap": "Увімкнути перенос рядків",
|
||||
"diffView.actions.openFileInEditorAtChange": "Відкрити цей файл у редакторі на зміні",
|
||||
|
||||
@@ -1175,6 +1175,8 @@ export const dict: Record<I18nKey, string> = {
|
||||
'diffView.actions.renderAnyway': '仍然渲染',
|
||||
'diffView.actions.expandAll': '全部展开',
|
||||
'diffView.actions.collapseAll': '全部折叠',
|
||||
'diffView.actions.loadFullFiles': '加载完整文件',
|
||||
'diffView.actions.disableFullFiles': '停止加载完整文件',
|
||||
'diffView.actions.disableLineWrap': '关闭自动换行',
|
||||
'diffView.actions.enableLineWrap': '开启自动换行',
|
||||
'diffView.actions.openFileInEditorAtChange': '在编辑器中打开此文件并定位变更',
|
||||
|
||||
@@ -1185,6 +1185,8 @@ export const dict: Record<I18nKey, string> = {
|
||||
'diffView.actions.renderAnyway': '仍然渲染',
|
||||
'diffView.actions.expandAll': '全部展開',
|
||||
'diffView.actions.collapseAll': '全部折疊',
|
||||
'diffView.actions.loadFullFiles': '載入完整檔案',
|
||||
'diffView.actions.disableFullFiles': '停止載入完整檔案',
|
||||
'diffView.actions.disableLineWrap': '關閉自動換行',
|
||||
'diffView.actions.enableLineWrap': '開啟自動換行',
|
||||
'diffView.actions.openFileInEditorAtChange': '在編輯器中開啟此檔案並定位變更',
|
||||
|
||||
Reference in New Issue
Block a user