-
Notifications
You must be signed in to change notification settings - Fork 649
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
Conversation
There was a problem hiding this 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("[[")) { |
There was a problem hiding this comment.
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)
packages/foam-vscode/src/utils.ts
Outdated
word = word.replace(/[-]/g, " "); | ||
|
||
// now capitalize every word | ||
const modifiedWord = word |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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, ""); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!
There was a problem hiding this 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"; |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!
There was a problem hiding this 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, ""); |
There was a problem hiding this comment.
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
packages/foam-vscode/src/utils.ts
Outdated
word = word.replace(/[-]/g, " "); | ||
|
||
// now capitalize every word | ||
const modifiedWord = word |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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, ""); |
There was a problem hiding this comment.
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!
packages/foam-vscode/src/utils.ts
Outdated
word = word.replace(/[-]/g, " "); | ||
|
||
// now capitalize every word | ||
const modifiedWord = word |
There was a problem hiding this comment.
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!
Chatted over Discord - good to merge! |
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