[WIP] Ability to insert code snippets into files (addresses Issue#1630) #1826
[WIP] Ability to insert code snippets into files (addresses Issue#1630) #1826
Conversation
Hey @twigz20 - really excited to see this. I'll try out your branch and get back to you with some design guidance sometime tomorrow. Thanks for your patience! |
Sorry for the delay @twigz20 - will tackle this today. |
@twigz20 Would you mind rebasing this to the latest master so it merges cleanly? |
Started a couple of issues related to this... Design of the Menu - #1826 |
This PR looks like it needs a rebase to make sure it stays in sync with master so it can be merged when it's ready |
@twigz20 how is this going? Looks like we've stalled a bit. |
eb28ded
to
1a83dd0
Compare
Hey @twigz20 - what's the state of this PR? Let me know how I can help - is it ready for testing? |
@flukeout Yes it is. Although i'd like to try using the design mockup you showed here: https://github.com/mozilla/thimble.mozilla.org/issues/1855 |
Awesome @twigz20 - looks like you got the 'detect file' functionality in there too! This is exciting. So how do you want to proceed? I'm happy to take over for a bit and add some styling / markup for the updated menu in #1855 or is that something you'd like to tackle? Let me know. I think we should go with this option... This allows people to copy & paste the code as well. While I like the 'flyout' preview - I think losing copy paste would be annoying. What do you think? In the meantime, I'll provide an icon for the snippet button shortly. |
Hey @twigz20 - just checking into the markup and noticed you're using tabs instead of spaces... Please switch to spaces for consistency. Cheers! |
OK, I made an icon - snippets-icon.zip Here's how it looks... Here's how to make it look like that...
|
@flukeout That would be very helpful if you were to take over a bit. Will make the appropriate changes! I'm working on trying to improve the efficiency of how I'm loading the snippets and creating the menus. I'm also trying to figure out a way to get the |
@gideonthomas to check in with @flukeout about markup for the dropdown |
@twigz20 I'm going to work on the menu on top of the current state of your branch and submit a PR against your working branch - sound good? I'll also include the icon for the dropdown menu. |
@flukeout Yes, thats sounds good! |
Hey @twigz20 - I made a PR against your working branch with the markup for the menu. It's got the icon and localized strings too. Should look like this... I'll let you sort out the functionality along with your other changes. The idea is that the snippet type will be preselected in the header depending on the type of file you have. HTML will be the default. The user should be able to toggle between the snippet types by clicking those options too. Let me know if you have any questions! |
@flukeout Thanks! I'll begin testing will let you know if I anything comes up! I do have 1 question. In |
Yeah, the |
So anyway, if you are able to get the different snippet types in there and update your PR, then I can take another design pass. |
@twigz20 let me know how far you get with implementing this with the approach I mentioned in class. |
@flukeout Alright, I've gotten a "dirty" implementation of it working with the new design markup. See below. @gideonthomas I've been attempting the method you suggested. However, as soon as i add in this 1 line So I'm not able to progress any further. Any ideas how I can solve this? @humphd in case you know about this as well! |
@twigz20 what's on your dev console when you load it? That error doesn't look like a require error but rather a network error. |
@humphd On first refresh my dev console displays this: Then with each refresh attempt, the dev console is blank It doesn't give me any information. |
I'd say your server isn't running. Better debug that, run |
@humphd After running |
|
6287102
to
08cb0bb
Compare
@gideonthomas Done. Let me know if i missed anything. |
@twigz20 awesome! Thanks! I'll open up a PR against your branch with a couple of changes. Thanks for getting all of this done! |
@twigz20 opened up a PR against your branch! |
Rely on templating to generate snippet element state
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.
@@ -3,6 +3,7 @@ define(function(require) { | |||
var $ = require("jquery"); | |||
var PopupMenu = require("fc/bramble-popupmenu"); | |||
var analytics = require("analytics"); | |||
var fileType = "HTML"; |
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.
you don't use this anymore so let's get rid of it.
server/lib/snippets.js
Outdated
} | ||
}]; | ||
|
||
const CSS = [{ |
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.
darn CSS
is an object on window
. @twigz20 I would advise that you make all of these lowercase throughout your code.
locales/en-US/messages.properties
Outdated
# Code Snippet Data | ||
snippetHTMLComment=Comment | ||
snippetHTMLCommentTitle=Add a Comment | ||
snippetHTMLCommentData=<!-- Your HTML comment here -->\n |
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.
@TheoChevalier I would love your input here. I'm not sure if this is a good way to localize code snippets that we can insert into Thimble's editor. I wanted to localize code snippets that have text content in them. However, each string has a bunch of \n
's in them as well as spaces before tag names for formatting purposes when they are rendered. I don't think I was able to come up with a way around this. Let me know what you think.
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 asking, @gideonthomas :) That’s indeed tricky, and I’m not sure there’s a perfect solution. Having a loooong string with lots of \n
and embedded code would work, technically, but I think what would be better here is extracting the text from the code snippets, then doing the formatting on the code side.
To be more explicit:
snippetHTMLCommentData=Your HTML comment here
In .js file, somewhere:
var myString = '<!--' + l10nLib.getString('snippetHTMLCommentData') + '-->\n';
Concatenating strings is generally a bad practice, but in this case it’s actually fine since we don’t want localizers to change the markup/code. Would that work with the rest of the snippets? It can be okay to include pieces of code when it makes string extraction easier, as long as there is a comment saying that this part should not be translated.
In the example above, we would add a comment explaining the context (concatenated with <!-- -->
)
Does that make sense, or maybe I’m missing something?
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.
no makes perfect sense! Thanks for the input! I think I'll go with that approach.
@gideonthomas Changes Made! |
@twigz20 awesome! Thanks, expect another PR (from me) to your branch soon which will incorporate the localization changes suggested above. |
Just an update to keep you in the loop @twigz20: @gideonthomas has created a branch with localization changes and we're working on it together to finish it up. Expect a PR against your branch within a day or so! Thanks for your patience - we are close! |
locales/en-US/messages.properties
Outdated
snippetJSIfElseData=if (condition1) {\n // instructions for condition 1\n} else if (condition2) {\n // instructions for condition 2\n} else {\n // fallback instructions\n}\n | ||
snippetJSComment=Comment | ||
snippetJSCommentTitle=Add a Comment | ||
snippetJSCommentData=/* Your Javascript comment here */\n |
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.
JavaScript
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 fixes @gideonthomas :) Had a quick look at the l10n part, everything looks good to me 👍
Thanks for the review :) |
Thanks a lot for the hard work @twigz20! You've added an amazing feature to Thimble :) |
@gideonthomas Thanks! I couldn't have done it without the support of the core team! |
Yeah awesome work @twigz20 - really happy we got this in! I changed a lot of the snippets, give them a try to see if they make sense or need some changes! 👍 💯 |
This is still a work in progress.
I've currently got the core functionality in place. However, I feel as though it lacks in terms of efficiency.
As you can see in the gif above there is a slight freeze in the UI after inserting a snippet. For the time being, I'm storing all the snippets in
snippets.js
. On initial load up of Thimble, I've set the default file type to beHTML
because there is no way to determine what file I'm on at that point in time.Afterward, whenever the file is changed
Thimble
receives anactiveEditorChanged
event which also comes with the full file name. With access to that information, I'm then able to identify the current file type and repopulate theli
elements of the snippets menu.Any further assistance would be highly appreciated.