Last active
November 2, 2019 18:59
-
-
Save execjosh/9679941 to your computer and use it in GitHub Desktop.
Block Cursor for Atom v0.75.0
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
--- a/Atom.app/Contents/Resources/app/src/cursor-view.js | |
+++ b/Atom.app/Contents/Resources/app/src/cursor-view.js | |
@@ -19,7 +19,12 @@ | |
"class": 'cursor idle' | |
}, (function(_this) { | |
return function() { | |
- return _this.raw(' '); | |
+ return _this.div({ | |
+ outlet: 'cursorValue', | |
+ 'style': 'visibility:hidden;' | |
+ }, function() { | |
+ return _this.raw(' '); | |
+ }); | |
}; | |
})(this)); | |
}; | |
@@ -96,6 +101,10 @@ | |
return this.stopBlinking(); | |
}; | |
+ CursorView.prototype.setCursorValue = function(value) { | |
+ this.cursorValue.html(value); | |
+ }; | |
+ | |
CursorView.prototype.updateDisplay = function() { | |
var pixelPosition, screenPosition; | |
screenPosition = this.getScreenPosition(); | |
--- a/editor-view.js | |
+++ b/editor-view.js | |
@@ -923,6 +923,30 @@ | |
})(this)); | |
}; | |
+ EditorView.prototype.getCharAtCursor = function() { | |
+ var editor = this.getEditor(); | |
+ var range = Range.fromPointWithDelta(editor.getCursorBufferPosition(), 0, 1); | |
+ return editor.getBuffer().getTextInRange(range); | |
+ }; | |
+ | |
+ EditorView.prototype.convertCharToCursorValue = function(ch) { | |
+ switch (ch) { | |
+ case '': | |
+ case '\n': | |
+ case '\r': | |
+ case ' ': | |
+ ch = ' '; | |
+ break; | |
+ case '\t': | |
+ ch = ' '; | |
+ for (var i = 1, tl = this.getEditor().getTabLength(); i < tl; i++) { | |
+ ch += ' '; | |
+ } | |
+ break; | |
+ } | |
+ return ch; | |
+ }; | |
+ | |
EditorView.prototype.handleInputEvents = function() { | |
var lastInput, selectedText; | |
this.on('cursor:moved', (function(_this) { | |
@@ -933,6 +957,9 @@ | |
} | |
cursorView = _this.getCursorView(); | |
if (cursorView.isVisible()) { | |
+ var ch = _this.getCharAtCursor(); | |
+ var value = _this.convertCharToCursorValue(ch); | |
+ cursorView.setCursorValue(value); | |
style = cursorView[0].style; | |
_this.hiddenInput[0].style.top = style.top; | |
return _this.hiddenInput[0].style.left = style.left; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment