Skip to content

Instantly share code, notes, and snippets.

@halfdan
Created October 3, 2016 22:04
Show Gist options
  • Save halfdan/e7ac5d94d2c72f33523f86f96518d686 to your computer and use it in GitHub Desktop.
Save halfdan/e7ac5d94d2c72f33523f86f96518d686 to your computer and use it in GitHub Desktop.
Text Editing
import Ember from 'ember';
export default Ember.Component.extend({
string: null,
selection: "",
actions: {
selectionChanged(event) {
let target = event.target,
string = this.get('string');
this.set('selection', string.substring(target.selectionStart, target.selectionEnd));
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
input {
width: 500px;
margin: 0 auto;
resize: none;
border: 1px solid grey;
border-radius: 10px;
padding: 5px;
text-align: center;
overflow: auto;
font-size: 2em;
}
input::selection {
background: yellow;
}
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{token-select string="This is a sentence"}}
<br>
<br>
<input type="text" onSelect={{action "selectionChanged"}} readonly value={{string}} />
{{selection}}
{
"version": "0.10.5",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.8.0",
"ember-data": "2.8.0",
"ember-template-compiler": "2.8.0",
"ember-testing": "2.8.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment