Make application aware it saved the buffer and not something else (#4314)
Make application aware it saved the buffer and something else
This commit is contained in:
@ -140,6 +140,13 @@ const FileTreeItem = ({
|
|||||||
async (eventType, path) => {
|
async (eventType, path) => {
|
||||||
// Don't try to read a file that was removed.
|
// Don't try to read a file that was removed.
|
||||||
if (isCurrentFile && eventType !== 'unlink') {
|
if (isCurrentFile && eventType !== 'unlink') {
|
||||||
|
// Prevents a cyclic read / write causing editor problems such as
|
||||||
|
// misplaced cursor positions.
|
||||||
|
if (codeManager.writeCausedByAppCheckedInFileTreeFileSystemWatcher) {
|
||||||
|
codeManager.writeCausedByAppCheckedInFileTreeFileSystemWatcher = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
let code = await window.electron.readFile(path, { encoding: 'utf-8' })
|
let code = await window.electron.readFile(path, { encoding: 'utf-8' })
|
||||||
code = normalizeLineEndings(code)
|
code = normalizeLineEndings(code)
|
||||||
codeManager.updateCodeStateEditor(code)
|
codeManager.updateCodeStateEditor(code)
|
||||||
|
@ -20,6 +20,8 @@ export default class CodeManager {
|
|||||||
private _hotkeys: { [key: string]: () => void } = {}
|
private _hotkeys: { [key: string]: () => void } = {}
|
||||||
private timeoutWriter: ReturnType<typeof setTimeout> | undefined = undefined
|
private timeoutWriter: ReturnType<typeof setTimeout> | undefined = undefined
|
||||||
|
|
||||||
|
public writeCausedByAppCheckedInFileTreeFileSystemWatcher = false
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
if (isDesktop()) {
|
if (isDesktop()) {
|
||||||
this.code = ''
|
this.code = ''
|
||||||
@ -120,6 +122,7 @@ export default class CodeManager {
|
|||||||
// and file-system watchers which read, will receive empty data during
|
// and file-system watchers which read, will receive empty data during
|
||||||
// writes.
|
// writes.
|
||||||
clearTimeout(this.timeoutWriter)
|
clearTimeout(this.timeoutWriter)
|
||||||
|
this.writeCausedByAppCheckedInFileTreeFileSystemWatcher = true
|
||||||
this.timeoutWriter = setTimeout(() => {
|
this.timeoutWriter = setTimeout(() => {
|
||||||
// Wait one event loop to give a chance for params to be set
|
// Wait one event loop to give a chance for params to be set
|
||||||
// Save the file to disk
|
// Save the file to disk
|
||||||
|
Reference in New Issue
Block a user