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

Remove Ivy Codemirror #14659

Merged
merged 17 commits into from
Mar 29, 2022
Merged

Remove Ivy Codemirror #14659

merged 17 commits into from
Mar 29, 2022

Conversation

Monkeychip
Copy link
Contributor

@Monkeychip Monkeychip commented Mar 23, 2022

Replacing the deprecated ivycodemirror with an ember modifier. See Deprecation and instructions here.

Notes:

  • This PR came about because of this issue. Unfortunately without having some regression issues there was no simple way to allow copying while also not showing the cursor. In order to do this we needed to remove IvyCodemirror.
  • We no longer use an options object.
  • This is our first custom modifier. If you're curious how they work, this documentation was very helpful.
  • This became a bigger PR than I had originally thought it would be. My apologies, but these changes should happen all at once.
Screen.Recording.2022-03-28.at.11.54.53.AM.mp4

@vercel vercel bot temporarily deployed to Preview – vault March 28, 2022 17:46 Inactive
@Monkeychip Monkeychip added the ui label Mar 28, 2022
@Monkeychip Monkeychip added this to the 1.11.0-rc1 milestone Mar 28, 2022
@Monkeychip Monkeychip marked this pull request as ready for review March 28, 2022 17:47
@vercel vercel bot temporarily deployed to Preview – vault-storybook March 28, 2022 17:54 Inactive
*/

const JSON_EDITOR_DEFAULTS = {
// IMPORTANT: `gutters` must come before `lint` since the presence of
Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved comment to the modifier.

@@ -168,31 +168,12 @@ $gutter-grey: #2a2f36;
}

.readonly-codemirror {
.CodeMirror-cursors {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this was not working. We have it working now under a new class that only shows if the editor is readOnly.

@@ -2,7 +2,10 @@
<JsonEditor
@showToolbar={{false}}
@value={{stringify this.content}}
@options={{hash readOnly=true lineNumbers=false autoHeight=true gutters=false theme="hashi auto-height"}}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

all options objects were spread out so that the individual properties were sent to the json-editor.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not seeing autoHeight as an arg. Is the codemirror default true and is that something we won't ever want to set to false?

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 catch. I removed this because before it was used to set the viewportMargin. See here

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahh ok I see now thanks!

@@ -19,8 +19,7 @@ module('Integration | Component | console/log json', function (hooks) {
this.set('content', objectContent);

await render(hbs`{{console/log-json content=content}}`);
const instance = this.codeMirror.instanceFor(find('[data-test-component=json-editor]').id);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this old way of selecting the codemirror instance no longer works. I suspect because we're initializing it through a modifier instead of on the component via ivycodemirror.

@@ -26,10 +26,6 @@ const appConfig = {
return `${config.rootURL.replace(/\/$/, '')}${filePath}`;
},
},
codemirror: {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

everything removed from this file was added into the modifier.

Copy link
Contributor

@zofskeez zofskeez left a comment

Choose a reason for hiding this comment

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

Great work on this thanks! Small wording issue on a comment and I wanted to get your thoughts on the mode arg before approving.

* @param {object} [options] - option object that overrides codemirror default options such as the styling.
* @param {Object} [extraKeys] - to provide keyboard shortcut methods for things like saving on shift + enter.
* @param {Array} [gutters] - An array of CSS class names or class name / CSS string pairs, each of which defines a width (and optionally a background), and which will be used to draw the background of the gutters.
* @param {string} [mode] - right now we only import ruby so must mode but be ruby or defaults to javascript. If you wanted another language you need to import it into the modifier.
Copy link
Contributor

Choose a reason for hiding this comment

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

Small nit on the comment wording. Also, from reading it I'm wondering since ruby and application/json are the only supported modes at this time could the arg change to useRubyMode or something like that? If true the mode is set to ruby otherwise application/json is used. What are your thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a valid question. I think however I prefer mode because it aligns with the codemirror property. It would be easy for someone to look up. I also don't want someone to think they only can use Ruby in the future. They can use lots of other options they just need to import it. They'll immediately error to if they use something other than ruby.

I'll amend the comment wording.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good so if I were to pass in php right now for example codemirror would throw an error since it's not imported?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

correct, it wouldn't work.

// `gutters` is cached internally when `lint` is toggled
gutters: this.args.named.gutters || ['CodeMirror-lint-markers'],
matchBrackets: true,
lint: { lintOnChange: true },
Copy link
Contributor

Choose a reason for hiding this comment

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

The previous version of JsonEditor had lintOnChange defaulted to false. Just want to verify that we want that as true in the new version.

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 catch. This was left over from me playing with the linting. I'll change.

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, strange. I changed back and it broke the linter. Let me investigate a little tomorrow because we are calling performLint() so we shouldn't need this.

@@ -2,7 +2,10 @@
<JsonEditor
@showToolbar={{false}}
@value={{stringify this.content}}
@options={{hash readOnly=true lineNumbers=false autoHeight=true gutters=false theme="hashi auto-height"}}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not seeing autoHeight as an arg. Is the codemirror default true and is that something we won't ever want to set to false?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants