-
-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds keyboard shortcut option to comment javascript code. (#622)
* adds shortcut comment option for javascript code * Adds test * change from `keypress` to `keydown` to trigger events * comment logic moved to initializer * fix test server shutdown
- Loading branch information
Showing
9 changed files
with
98 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export function initialize(/* application */) { | ||
// adds "toggleCommentIndented" command to codemirror for default keymap | ||
|
||
if (CodeMirror) { | ||
CodeMirror.keyMap.default['Cmd-/'] = 'toggleCommentIndented'; | ||
} | ||
} | ||
|
||
export default { | ||
initialize | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { test } from 'qunit'; | ||
import moduleForAcceptance from 'ember-twiddle/tests/helpers/module-for-acceptance'; | ||
|
||
moduleForAcceptance('Acceptance | code comment'); | ||
|
||
test('checks javascript comment option', async function(assert) { | ||
const files = [ | ||
{ | ||
filename: "application.controller.js", | ||
content: `import Ember from "ember"; | ||
export default Ember.Controller.extend({ | ||
appName: 'Ember Twiddle' | ||
});` | ||
}, | ||
{ | ||
filename: "application.template.hbs", | ||
content: "Welcome to {{appName}}" | ||
} | ||
]; | ||
|
||
|
||
await runGist(files); | ||
|
||
let textboxNode = 'textarea:eq(1)'; | ||
textboxNode = '.CodeMirror textarea'; | ||
await click(textboxNode); | ||
|
||
await triggerEvent(textboxNode, 'keydown', { | ||
keyCode: 65, // 'A' | ||
metaKey: true | ||
}); | ||
|
||
await triggerEvent(textboxNode, 'keydown', { | ||
keyCode: 191, // '/' | ||
metaKey: true | ||
}); | ||
|
||
let [firstLine] = find('.CodeMirror-line'); | ||
let content = firstLine.textContent; | ||
|
||
assert.ok(content.startsWith('//'), 'Line has been commented'); | ||
|
||
await triggerEvent(textboxNode, 'keydown', { | ||
keyCode: 191, // '/' | ||
metaKey: true | ||
}); | ||
|
||
[firstLine] = find('.CodeMirror-line'); | ||
content = firstLine.textContent; | ||
|
||
assert.notOk(content.startsWith('//'), 'Line has been uncommented'); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import Application from '@ember/application'; | ||
import { run } from '@ember/runloop'; | ||
|
||
import { initialize } from 'ember-twiddle/initializers/app-initializer'; | ||
import { module, test } from 'qunit'; | ||
import destroyApp from '../../helpers/destroy-app'; | ||
|
||
module('Unit | Initializer | app initializer', { | ||
beforeEach() { | ||
run(() => { | ||
this.application = Application.create(); | ||
this.application.deferReadiness(); | ||
}); | ||
}, | ||
afterEach() { | ||
destroyApp(this.application); | ||
} | ||
}); | ||
|
||
// Replace this with your real tests. | ||
test('it works', function(assert) { | ||
initialize(this.application); | ||
|
||
// you would normally confirm the results of the initializer here | ||
assert.ok(true); | ||
}); |