Skip to content

Commit

Permalink
fix: don't open diff for binary files, just open them instead
Browse files Browse the repository at this point in the history
close #801
  • Loading branch information
Vinzent03 committed Dec 28, 2024
1 parent 16f0bd9 commit 4c102fb
Show file tree
Hide file tree
Showing 5 changed files with 333 additions and 9 deletions.
267 changes: 267 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,270 @@ RESPONSE=$(cat "$TEMP_FILE.response")
echo "$RESPONSE"
`;

/**
* Copied from https://github.com/sindresorhus/binary-extensions/blob/main/binary-extensions.json
*/
export const BINARY_EXTENSIONS = [
"3dm",
"3ds",
"3g2",
"3gp",
"7z",
"a",
"aac",
"adp",
"afdesign",
"afphoto",
"afpub",
"ai",
"aif",
"aiff",
"alz",
"ape",
"apk",
"appimage",
"ar",
"arj",
"asf",
"au",
"avi",
"bak",
"baml",
"bh",
"bin",
"bk",
"bmp",
"btif",
"bz2",
"bzip2",
"cab",
"caf",
"cgm",
"class",
"cmx",
"cpio",
"cr2",
"cur",
"dat",
"dcm",
"deb",
"dex",
"djvu",
"dll",
"dmg",
"dng",
"doc",
"docm",
"docx",
"dot",
"dotm",
"dra",
"DS_Store",
"dsk",
"dts",
"dtshd",
"dvb",
"dwg",
"dxf",
"ecelp4800",
"ecelp7470",
"ecelp9600",
"egg",
"eol",
"eot",
"epub",
"exe",
"f4v",
"fbs",
"fh",
"fla",
"flac",
"flatpak",
"fli",
"flv",
"fpx",
"fst",
"fvt",
"g3",
"gh",
"gif",
"graffle",
"gz",
"gzip",
"h261",
"h263",
"h264",
"icns",
"ico",
"ief",
"img",
"ipa",
"iso",
"jar",
"jpeg",
"jpg",
"jpgv",
"jpm",
"jxr",
"key",
"ktx",
"lha",
"lib",
"lvp",
"lz",
"lzh",
"lzma",
"lzo",
"m3u",
"m4a",
"m4v",
"mar",
"mdi",
"mht",
"mid",
"midi",
"mj2",
"mka",
"mkv",
"mmr",
"mng",
"mobi",
"mov",
"movie",
"mp3",
"mp4",
"mp4a",
"mpeg",
"mpg",
"mpga",
"mxu",
"nef",
"npx",
"numbers",
"nupkg",
"o",
"odp",
"ods",
"odt",
"oga",
"ogg",
"ogv",
"otf",
"ott",
"pages",
"pbm",
"pcx",
"pdb",
"pdf",
"pea",
"pgm",
"pic",
"png",
"pnm",
"pot",
"potm",
"potx",
"ppa",
"ppam",
"ppm",
"pps",
"ppsm",
"ppsx",
"ppt",
"pptm",
"pptx",
"psd",
"pya",
"pyc",
"pyo",
"pyv",
"qt",
"rar",
"ras",
"raw",
"resources",
"rgb",
"rip",
"rlc",
"rmf",
"rmvb",
"rpm",
"rtf",
"rz",
"s3m",
"s7z",
"scpt",
"sgi",
"shar",
"snap",
"sil",
"sketch",
"slk",
"smv",
"snk",
"so",
"stl",
"suo",
"sub",
"swf",
"tar",
"tbz",
"tbz2",
"tga",
"tgz",
"thmx",
"tif",
"tiff",
"tlz",
"ttc",
"ttf",
"txz",
"udf",
"uvh",
"uvi",
"uvm",
"uvp",
"uvs",
"uvu",
"viv",
"vob",
"war",
"wav",
"wax",
"wbmp",
"wdp",
"weba",
"webm",
"webp",
"whl",
"wim",
"wm",
"wma",
"wmv",
"wmx",
"woff",
"woff2",
"wrm",
"wvx",
"xbm",
"xif",
"xla",
"xlam",
"xls",
"xlsb",
"xlsm",
"xlsx",
"xlt",
"xltm",
"xltx",
"xm",
"xmind",
"xpi",
"xpm",
"xwd",
"xz",
"z",
"zip",
"zipx",
];
19 changes: 16 additions & 3 deletions src/ui/history/components/logFileComponent.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<script lang="ts">
import { setIcon, TFile } from "obsidian";
import type { DiffFile } from "src/types";
import { getDisplayPath, getNewLeaf, mayTriggerFileMenu } from "src/utils";
import {
fileIsBinary,
getDisplayPath,
getNewLeaf,
mayTriggerFileMenu,
} from "src/utils";
import type HistoryView from "../historyView";
export let diff: DiffFile;
Expand All @@ -16,6 +21,14 @@
0
);
function mainClick(event: MouseEvent) {
if (fileIsBinary(diff.path)) {
open(event);
} else {
showDiff(event);
}
}
function open(event: MouseEvent) {
const file = view.app.vault.getAbstractFileByPath(diff.vault_path);
Expand All @@ -41,7 +54,7 @@
<!-- svelte-ignore a11y-no-static-element-interactions -->
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
<main
on:click|stopPropagation={showDiff}
on:click|stopPropagation={mainClick}
on:auxclick|stopPropagation={(event) => {
if (event.button == 2)
mayTriggerFileMenu(
Expand All @@ -51,7 +64,7 @@
view.leaf,
"git-history"
);
else showDiff(event);
else mainClick(event);
}}
on:focus
class="tree-item nav-file"
Expand Down
19 changes: 16 additions & 3 deletions src/ui/sourceControl/components/fileComponent.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
import type { GitManager } from "src/gitManager/gitManager";
import type { FileStatusResult } from "src/types";
import { DiscardModal } from "src/ui/modals/discardModal";
import { getDisplayPath, getNewLeaf, mayTriggerFileMenu } from "src/utils";
import {
fileIsBinary,
getDisplayPath,
getNewLeaf,
mayTriggerFileMenu,
} from "src/utils";
import type GitView from "../sourceControl";
export let change: FileStatusResult;
Expand All @@ -20,6 +25,14 @@
0
);
function mainClick(event: MouseEvent) {
if (fileIsBinary(change.path)) {
open(event);
} else {
showDiff(event);
}
}
function hover(event: MouseEvent) {
//Don't show previews of config- or hidden files.
if (view.app.vault.getAbstractFileByPath(change.vault_path)) {
Expand Down Expand Up @@ -86,7 +99,7 @@
<!-- svelte-ignore a11y-unknown-aria-attribute -->
<main
on:mouseover={hover}
on:click|stopPropagation={showDiff}
on:click|stopPropagation={mainClick}
on:auxclick|stopPropagation={(event) => {
if (event.button == 2)
mayTriggerFileMenu(
Expand All @@ -96,7 +109,7 @@
view.leaf,
"git-source-control"
);
else showDiff(event);
else mainClick(event);
}}
on:focus
class="tree-item nav-file"
Expand Down
Loading

0 comments on commit 4c102fb

Please sign in to comment.