8000 Renaming tabs/files will now reflect on the other view. · arduino/lab-micropython-editor@828f21b · GitHub
[go: up one dir, main page]

Skip to content

Commit 828f21b

Browse files
committed
Renaming tabs/files will now reflect on the other view.
Signed-off-by: ubi de feo <me@ubidefeo.com>
1 parent aa91886 commit 828f21b

File tree

1 file changed

+35
-38
lines changed

1 file changed

+35
-38
lines changed

ui/arduino/store.js

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,12 @@ async function store(state, emitter) {
927927
)
928928
)
929929
}
930+
// Update tab is renaming successful
931+
const tabToRenameIndex = state.openFiles.findIndex(f => f.fileName === file.fileName && f.source === file.source && f.parentFolder === file.parentFolder)
932+
if (tabToRenameIndex > -1) {
933+
state.openFiles[tabToRenameIndex].fileName = value
934+
emitter.emit('render')
935+
}
930936
} catch (e) {
931937
alert(`The file ${file.fileName} could not be renamed to ${value}`)
932938
}
@@ -955,17 +961,6 @@ async function store(state, emitter) {
955961
return
956962
}
957963

958-
let response = canSave({
959-
view: state.view,
960-
isConnected: state.isConnected,
961-
openFiles: state.openFiles,
962-
editingFile: state.editingFile
963-
})
964-
if (response == false) {
965-
log("can't save")
966-
return
967-
}
968-
969964
state.isSaving = true
970965
emitter.emit('render')
971966

@@ -1037,34 +1032,36 @@ async function store(state, emitter) {
10371032

10381033
if (fullPathExists) {
10391034
// SAVE FILE CONTENTS
1040-
const contents = openFile.editor.editor.state.doc.toString()
1041-
try {
1042-
if (openFile.source == 'board') {
1043-
await serialBridge.getPrompt()
1044-
await serialBridge.saveFileContent(
1045-
serialBridge.getFullPath(
1046-
state.boardNavigationRoot,
1047-
openFile.parentFolder,
1048-
oldName
1049-
),
1050-
contents,
1051-
(e) => {
1052-
state.savingProgress = e
1053-
emitter.emit('render')
1054-
}
1055-
)
1056-
} else if (openFile.source == 'disk') {
1057-
await disk.saveFileContent(
1058-
disk.getFullPath(
1059-
state.diskNavigationRoot,
1060-
openFile.parentFolder,
1061-
oldName
1062-
),
1063-
contents
1064-
)
1035+
if (openFile.hasChanges) {
1036+
const contents = openFile.editor.editor.state.doc.toString()
1037+
try {
1038+
if (openFile.source == 'board') {
1039+
await serialBridge.getPrompt()
1040+
await serialBridge.saveFileContent(
1041+
serialBridge.getFullPath(
1042+
state.boardNavigationRoot,
1043+
openFile.parentFolder,
1044+
oldName
1045+
),
1046+
contents,
1047+
(e) => {
1048+
state.savingProgress = e
1049+
emitter.emit('render')
1050+
}
1051+
)
1052+
} else if (openFile.source == 'disk') {
1053+
await disk.saveFileContent(
1054+
disk.getFullPath(
1055+
state.diskNavigationRoot,
1056+
openFile.parentFolder,
1057+
oldName
1058+
),
1059+
contents
1060+
)
1061+
}
1062+
} catch (e) {
1063+
log('error', e)
10651064
}
1066-
} catch (e) {
1067-
log('error', e)
10681065
}
10691066
// RENAME FILE
10701067
try {

0 commit comments

Comments
 (0)
0