summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-03-18 13:03:10 -0700
committerAlex Yatskov <alex@foosoft.net>2016-03-18 13:03:10 -0700
commit81ded4fb78cf32a3d85882708e2f651608100815 (patch)
tree26ded510365650ba6516dfa03228a424984e0522
parent3fd7ab16ac6f3c97822951eaddd7d9a090cea48a (diff)
WIP
-rw-r--r--content.js37
1 files changed, 16 insertions, 21 deletions
diff --git a/content.js b/content.js
index 119fce55..e3ac0998 100644
--- a/content.js
+++ b/content.js
@@ -20,32 +20,27 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-function insertBreakAtPoint(e) {
- var range;
- var textNode;
- var offset;
+function getText(e, length) {
+ let range = document.caretRangeFromPoint(e.clientX, e.clientY);
- if (document.caretPositionFromPoint) {
- range = document.caretPositionFromPoint(e.clientX, e.clientY);
- textNode = range.offsetNode;
- offset = range.offset;
- } else if (document.caretRangeFromPoint) {
- range = document.caretRangeFromPoint(e.clientX, e.clientY);
- textNode = range.startContainer;
- offset = range.startOffset;
+ let node = range.startContainer;
+ if (node.nodeType !== 3 /* TEXT_NODE */) {
+ return '';
}
- // only split TEXT_NODEs
- if (textNode.nodeType == 3) {
- var replacement = textNode.splitText(offset);
- var br = document.createElement('br');
- textNode.parentNode.insertBefore(br, replacement);
- }
+ let scan = Math.min(- range.startOffset, length);
+ console.log(scan);
+ range.setEnd(node, range.startOffset + scan);
+
+ return range.toString();
}
-function onMouseDown(e) {
- insertBreakAtPoint(e);
+function onMouseMove(e) {
+ const text = getText(e);
+ if (text !== '') {
+ console.log(text);
+ }
}
-window.addEventListener('mousedown', onMouseDown, false);
+window.addEventListener('mousemove', onMouseMove, false);