Skip to content

Commit

Permalink
Merge pull request #12 from obgnail/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
obgnail authored Jul 15, 2023
2 parents 4b11879 + b1bb379 commit 4f47451
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 69 deletions.
2 changes: 1 addition & 1 deletion plugin/commander.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
}
}

const _getFile = () => File.filePath || File.bundle?.filePath;
const _getFile = () => File.filePath || (File.bundle && File.bundle.filePath);
const getFile = shell => convertPath(_getFile(), shell);
const getFolder = shell => convertPath(Package.path.dirname(_getFile()), shell);
const getMountFolder = shell => convertPath(File.getMountFolder(), shell);
Expand Down
2 changes: 1 addition & 1 deletion plugin/copy_code.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
}

const _timer = setInterval(() => {
if (File?.editor?.fences?.addCodeBlock) {
if (File && File.editor && File.editor.fences && File.editor.fences.addCodeBlock) {
clearInterval(_timer);
File.editor.fences.addCodeBlock = decorator(File.editor.fences.addCodeBlock, after);
}
Expand Down
18 changes: 10 additions & 8 deletions plugin/file_counter.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,13 @@
})

const children = getChild(treeNode, "file-node-children");
children?.children.forEach(child => {
if (child.getAttribute("data-has-sub") === "true") {
setDirCount(child);
}
})
if (children && children.children) {
children.children.forEach(child => {
if (child.getAttribute("data-has-sub") === "true") {
setDirCount(child);
}
})
}
}

const setAllDirCount = () => {
Expand All @@ -113,15 +115,15 @@
new MutationObserver(mutationList => {
if (mutationList.length === 1) {
const add = mutationList[0].addedNodes[0];
if (add?.classList?.contains("file-library-node")) {
if (add && add.classList && add.classList.contains("file-library-node")) {
setDirCount(add);
return
}
}

for (const mutation of mutationList) {
if (mutation.target?.classList?.contains("typora-file-count")
|| mutation.addedNodes[0]?.classList?.contains("typora-file-count")) {
if (mutation.target && mutation.target.classList && mutation.target.classList.contains("typora-file-count")
|| mutation.addedNodes[0] && mutation.addedNodes[0].classList && mutation.addedNodes[0].classList.contains("typora-file-count")) {
continue
}
setAllDirCount();
Expand Down
2 changes: 1 addition & 1 deletion plugin/md_padding/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
}

const metaKeyPressed = ev => Package.File.isMac ? ev.metaKey : ev.ctrlKey;
const getFilePath = () => Package.File.filePath || Package.File.bundle?.filePath;
const getFilePath = () => Package.File.filePath || Package.File.bundle && Package.File.bundle.filePath;
const read = filepath => Package.Fs.readFileSync(filepath, 'utf-8');
const write = (filepath, content) => Package.Fs.writeFileSync(filepath, content);
const save = () => File.saveUseNode();
Expand Down
32 changes: 0 additions & 32 deletions plugin/md_padding/md-padding/.eslintrc.json

This file was deleted.

20 changes: 0 additions & 20 deletions plugin/md_padding/md-padding/tsconfig.json

This file was deleted.

9 changes: 6 additions & 3 deletions plugin/window_tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@
const stopCount = 3;
const scrollTop = activeTab.scrollTop;
const _timer = setInterval(() => {
const filePath = File?.filePath || File.bundle?.filePath;
const filePath = File && File.filePath || File && File.bundle && File.bundle.filePath;
if (filePath === activeTab.path && entities.content.scrollTop !== scrollTop) {
entities.content.scrollTop = scrollTop;
count = 0;
Expand Down Expand Up @@ -306,7 +306,7 @@

File.editor.library.openFile = decorator(File.editor.library.openFile, after);

const filePath = File.filePath || File.bundle?.filePath;
const filePath = File.filePath || File.bundle && File.bundle.filePath;
if (filePath) {
openTab(filePath);
}
Expand Down Expand Up @@ -372,7 +372,10 @@
ev.stopPropagation();

if (close) {
entities.tabBar.querySelector(".tab-container.active")?.querySelector(".close-button").click();
const activeTab = entities.tabBar.querySelector(".tab-container.active");
if (activeTab) {
activeTab.querySelector(".close-button").click();
}
} else {
if (ev.shiftKey) {
tabUtil.activeIdx = (tabUtil.activeIdx === 0) ? tabUtil.tabs.length - 1 : tabUtil.activeIdx - 1;
Expand Down
16 changes: 13 additions & 3 deletions plugin/window_tab_old/window_tab_drag.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,21 @@
const execForAllWindows = js => Package.Client.execForAll(js);

const getAPP = () => Package.getElectron().app;
const getBrowserWindow = () => Package.getElectron()?.BrowserWindow;
const getBrowserWindow = () => {
const electron = Package.getElectron();
if (electron) {
return electron.BrowserWindow;
}
}
const getIPC = () => Package.getElectron().ipcMain;

const getAllWindows = () => getBrowserWindow().getAllWindows();
const getFocusedWindow = () => getBrowserWindow()?.getFocusedWindow();
const getFocusedWindow = () => {
const browserWindow = getBrowserWindow();
if (browserWindow) {
return browserWindow.getFocusedWindow();
}
}
const setFocusWindow = winId => {
const windows = getAllWindows();
for (const win of windows) {
Expand Down Expand Up @@ -389,7 +399,7 @@
}

global._openFileInNewWindow = () => {
const filePath = Package.File.filePath || Package.File.bundle?.filePath;
const filePath = Package.File.filePath || (Package.File.bundle && Package.File.bundle.filePath);
if (filePath) {
Package.File.editor.library.openFileInNewWindow(filePath, false);
} else {
Expand Down

0 comments on commit 4f47451

Please sign in to comment.