Skip to content

Commit 604714d

Browse files
committed
feat: improved copy api
1 parent afe9eda commit 604714d

File tree

4 files changed

+55
-45
lines changed

4 files changed

+55
-45
lines changed

src/lib/editorFile.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,9 @@ export default class EditorFile {
748748
editorManager.container.parentElement.appendChild(this.content);
749749
}
750750
}
751-
editor?.selection.clearSelection();
751+
if (activeFile && activeFile.type === "editor") {
752+
activeFile.session.selection.clearSelection();
753+
}
752754
}
753755

754756
this.#tab.classList.add("active");

src/lib/editorManager.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,9 @@ async function EditorManager($header, $body) {
660660
$container.parentElement.appendChild(file.content);
661661
}
662662
}
663-
editor?.selection.clearSelection();
663+
if (manager.activeFile && manager.activeFile.type === "editor") {
664+
manager.activeFile.session.selection.clearSelection();
665+
}
664666
}
665667

666668
$header.text = file.filename;

src/plugins/sftp/src/com/foxdebug/sftp/Sftp.java

Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -599,51 +599,57 @@ public void run() {
599599
String source = args.optString(0);
600600
String destination = args.optString(1);
601601

602-
if (ssh == null || sftp == null) {
603-
callback.error("Not connected");
604-
return;
605-
}
606-
607-
try {
608-
copyRecursively(source, destination);
609-
callback.success();
610-
} catch (Exception e) {
611-
callback.error("Copy failed: " + errMessage(e));
612-
}
613-
} catch (Exception e) {
614-
callback.error(errMessage(e));
615-
}
616-
}
617-
618-
private void copyRecursively(String source, String destination)
619-
throws SftpStatusException, SshException, IOException {
620-
SftpFileAttributes attrs = sftp.stat(source);
602+
if (ssh != null && sftp != null) {
603+
try {
604+
SftpFileAttributes sourceAttrs = sftp.stat(source);
621605

622-
if (attrs.isDirectory()) {
623-
try {
624-
sftp.mkdir(destination);
625-
} catch (SftpStatusException e) {
626-
// Directory may already exist - ignore
627-
}
606+
if (sourceAttrs.isFile()) {
607+
// file copy
608+
try (java.io.InputStream in = sftp.getInputStream(source)) {
609+
sftp.put(in, destination);
610+
}
611+
} else if (sourceAttrs.isDirectory()) {
612+
// directory copy
613+
sftp.mkdir(destination);
614+
615+
for (SftpFile file : sftp.ls(source)) {
616+
String filename = file.getFilename();
617+
if (!filename.equals(".") && !filename.equals("..")) {
618+
String sourcePath = source + "/" + filename;
619+
String destPath = destination + "/" + filename;
620+
621+
if (file.getAttributes().isDirectory()) {
622+
// Recursively copy subdirectories
623+
JSONArray subDirArgs = new JSONArray();
624+
subDirArgs.put(sourcePath);
625+
subDirArgs.put(destPath);
626+
copy(subDirArgs, callback);
627+
} else {
628+
// Copy files within directory
629+
try (
630+
java.io.InputStream in = sftp.getInputStream(
631+
sourcePath
632+
)
633+
) {
634+
sftp.put(in, destPath);
635+
}
636+
}
637+
}
638+
}
639+
}
628640

629-
// Copy directory contents
630-
for (SftpFile file : sftp.ls(source)) {
631-
String filename = file.getFilename();
632-
if (!filename.equals(".") && !filename.equals("..")) {
633-
String srcPath = source + "/" + filename;
634-
String destPath = destination + "/" + filename;
635-
copyRecursively(srcPath, destPath);
641+
callback.success();
642+
return;
643+
} catch (SftpStatusException e) {
644+
callback.error("Source does not exist: " + errMessage(e));
645+
return;
636646
}
637647
}
638-
} else {
639-
// Copy file using buffered streams
640-
try (
641-
java.io.InputStream in = sftp.getInputStream(source);
642-
java.io.BufferedInputStream bis =
643-
new java.io.BufferedInputStream(in)
644-
) {
645-
sftp.put(bis, destination);
646-
} catch (TransferCancelledException e) {}
648+
callback.error("Not connected");
649+
} catch (
650+
SshException | IOException | TransferCancelledException e
651+
) {
652+
callback.error(errMessage(e));
647653
}
648654
}
649655
}

src/plugins/sftp/www/sftp.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ module.exports = {
4242
rename: function (oldpath, newpath, onSuccess, onFail) {
4343
cordova.exec(onSuccess, onFail, 'Sftp', 'rename', [oldpath, newpath]);
4444
},
45-
copy: function (sourcePath, destinationPath, onSuccess, onFail) {
46-
cordova.exec(onSuccess, onFail, 'Sftp', 'copy', [sourcePath, destinationPath]);
45+
copy: function (source, destination, onSuccess, onFail) {
46+
cordova.exec(onSuccess, onFail, 'Sftp', 'copy', [source, destination]);
4747
},
4848
pwd: function (onSuccess, onFail) {
4949
cordova.exec(onSuccess, onFail, 'Sftp', 'pwd', []);

0 commit comments

Comments
 (0)