Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(vscode): add command "Copy To Clipboard Without Brackets #274

Merged
merged 4 commits into from
Oct 6, 2020

Conversation

jsjoeio
Copy link
Contributor

@jsjoeio jsjoeio commented Oct 3, 2020

This adds a new command for foam-vscode called "Copy To Clipboard Without Brackets". I discussed this in the Foam Discord a while back, asking if this should be an outside thing (separate extension) or added as a feature to the core extension. It was suggested to do the later.

Use Case

Sometimes when drafting messages to people in Foam, I use references. Instead of sending them the messages with the brackets or removing them, I thought it would be nice to have this command which copies to clipboard and removes them for you.

Demo

2020-10-02 20 15 34

Copy link
Collaborator

@riccardoferretti riccardoferretti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks really good to me.
I have only left a couple of comments around some edge cases or minor points.


// loop through words
const modifiedWords = stringSplitBySpace.map(currentWord => {
if (currentWord.includes("[[")) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we happy with not supporting spaces in the file name/path?
(Even not taking into consideration aliases which we don't support yet)

word = word.replace(/[-]/g, " ");

// now capitalize every word
const modifiedWord = word
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically are we "deslugifying" here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! Exactly! I can update the comments to make that more obvious. Happy to even break it into a small function called deslugify

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually...it title cases the word, so I broke it out into a function, added more comments and a few tests. Good callout!

if (currentWord.includes("[[")) {
let word = currentWord.replace(/(\[\[)/g, "");
word = word.replace(/(\]\])/g, "");
word = word.replace(/(.mdx|.md|.markdown)/g, "");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have this list somewhere already? Should we consolidate it or do you think it's better to keep things more decoupled at the moment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call! I didn't even think to check. I'll look and if it is, I'll use that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I found it inside docs/_layouts/foam.html, but can't export it because it's just in a script tag in an HTML file 🤔

I'm not seeing it elsewhere...I'm going to leave for now, but if you see a better option, let me know and I'll happily change it!

Copy link
Member

@ingalless ingalless left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! Very useful command

it("removes the brackets", () => {
const input = "hello world [[this-is-it]]";
const actual = removeBrackets(input);
const expected = "hello world This Is It";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it isn't for this PR, but I sometimes name files differently to my heading, so I would want to grab the title. Is that an easy change? No worries if not but just floating it...
Like the tests though!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's actually a very good point, especially if we already have the definitions. And will probably leverage more the foam metadata as opposed to simply the markdown itself

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! I didn't even think about.

Is that an easy change?

I don't know 😅 More than happy to accept change if one of y'all want to do it!

Copy link
Contributor Author

@jsjoeio jsjoeio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the specific feedback @ingalless and @riccardoferretti ! 🙌🏼

I responded and made a few changes. Feel free to take another look! If there's changes to be made, hit the "request changes". If it's ready to go by chance, feel free to merge!

if (currentWord.includes("[[")) {
let word = currentWord.replace(/(\[\[)/g, "");
word = word.replace(/(\]\])/g, "");
word = word.replace(/(.mdx|.md|.markdown)/g, "");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call! I didn't even think to check. I'll look and if it is, I'll use that

word = word.replace(/[-]/g, " ");

// now capitalize every word
const modifiedWord = word
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! Exactly! I can update the comments to make that more obvious. Happy to even break it into a small function called deslugify

it("removes the brackets", () => {
const input = "hello world [[this-is-it]]";
const actual = removeBrackets(input);
const expected = "hello world This Is It";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! I didn't even think about.

Is that an easy change?

I don't know 😅 More than happy to accept change if one of y'all want to do it!

if (currentWord.includes("[[")) {
let word = currentWord.replace(/(\[\[)/g, "");
word = word.replace(/(\]\])/g, "");
word = word.replace(/(.mdx|.md|.markdown)/g, "");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I found it inside docs/_layouts/foam.html, but can't export it because it's just in a script tag in an HTML file 🤔

I'm not seeing it elsewhere...I'm going to leave for now, but if you see a better option, let me know and I'll happily change it!

word = word.replace(/[-]/g, " ");

// now capitalize every word
const modifiedWord = word
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually...it title cases the word, so I broke it out into a function, added more comments and a few tests. Good callout!

@jsjoeio
Copy link
Contributor Author

jsjoeio commented Oct 6, 2020

Chatted over Discord - good to merge!

@jsjoeio jsjoeio merged commit 3985427 into master Oct 6, 2020
@jsjoeio jsjoeio deleted the jsjoeio/copy-wo-brackets branch October 6, 2020 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants