CodeEdit icon indicating copy to clipboard operation
CodeEdit copied to clipboard

Creating a new file with clipboard contents

Open Syrux64 opened this issue 10 months ago • 6 comments

Description

This WIP PR does the following:

  • A new file can be created with the contents on the clipboard using menu action.
  • PTAL and LMK if I can proceed to implement this with shortcut key.

Related Issue

  • Addresses #1970

Screenshot

https://github.com/user-attachments/assets/79d42cdf-d88d-46ff-b8bd-11c4ae640333

Potential Bugs to fix

  • New file not being opened in new tab.

Syrux64 avatar Feb 23 '25 10:02 Syrux64

@Syrux64 looks great so far. Yeah go ahead and implement the keyboard shortcut for this. When the navigator is in focus and cmd V is pressed, it should create the file inside the selected folder. If a file is selected, the newly created file should be a sibling to the selected file both having the same parent folder.

austincondiff avatar Feb 24 '25 07:02 austincondiff

@austincondiff Sure! Thanks for the heads up.

Syrux64 avatar Feb 24 '25 11:02 Syrux64

This looks good so far! If you want to merge this before finishing the key command that would be fine.

My one suggestion is you can remove your new file method and just add a new contents parameter to the addFile method, with a default value of nil. That should make it so we don't have multiple addFile-type methods which could get messy.

    func addFile(
        fileName: String,
        toFile file: CEWorkspaceFile,
        useExtension: String? = nil,
        contents: Data? = nil // Shouldn't break any existing calls, reduces duplicate code.
    ) throws -> CEWorkspaceFile {

thecoolwinter avatar Feb 28 '25 01:02 thecoolwinter

@thecoolwinter thanks for pointing that out 👍, I'll get that fixed and raise a PR once I've implemented the shortcut.

Syrux64 avatar Mar 06 '25 04:03 Syrux64

Where are we on this? I'd love to get this merged soon. Really great work here!

austincondiff avatar May 12 '25 14:05 austincondiff

Sorry for the long delay. So far the menu action works fine. I tried adding shortcut key via NSItem's 'Key' attribute. But all I hear is a tick sound. Can you guys suggest any other way to accomplish this? Or we could merge this PR without a shortcut key feature.

Syrux64 avatar May 25 '25 19:05 Syrux64

No worries, I had lost track of this PR. I've got a commit that fixes the issue you found with the key-commands. I'm going to try and globally fix the race error you found with renaming files, as it's an issue elsewhere. I also went ahead and changed the key command to ⌘V to match Xcode. Thank you for getting this done and sorry for the wait!!

thecoolwinter avatar Jun 10 '25 19:06 thecoolwinter

@allcontributors please add @Syrux64 for code

thecoolwinter avatar Jun 11 '25 15:06 thecoolwinter

@thecoolwinter

I've put up a pull request to add @Syrux64! :tada:

allcontributors[bot] avatar Jun 11 '25 15:06 allcontributors[bot]

Thanks y'all for letting me contribute to this project. I learnt a lot <33

Syrux64 avatar Jun 11 '25 16:06 Syrux64