InlineEdit: Make cursor blink rate customizable

Codemirror supports out of the box customizability of cursor blink
rate. Half-period in milliseconds is used for cursor blinking. The
default blink rate in Codemirror is 530ms. Default in inline editor
is 0: blinking is disabled.

Change-Id: Ie54063f3ba11e98dcebaf727e29b50093258c028
This commit is contained in:
David Ostrovsky
2015-05-14 23:25:06 +02:00
parent c4e01806ff
commit 85f843a657
7 changed files with 34 additions and 1 deletions

View File

@@ -56,6 +56,7 @@ class EditPreferencesBox extends Composite {
@UiField Anchor close;
@UiField NpIntTextBox tabWidth;
@UiField NpIntTextBox lineLength;
@UiField NpIntTextBox cursorBlinkRate;
@UiField ToggleButton topMenu;
@UiField ToggleButton syntaxHighlighting;
@UiField ToggleButton showTabs;
@@ -78,6 +79,7 @@ class EditPreferencesBox extends Composite {
tabWidth.setIntValue(prefs.tabSize());
lineLength.setIntValue(prefs.lineLength());
cursorBlinkRate.setIntValue(prefs.cursorBlinkRate());
topMenu.setValue(!prefs.hideTopMenu());
syntaxHighlighting.setValue(prefs.syntaxHighlighting());
showTabs.setValue(prefs.showTabs());
@@ -105,6 +107,17 @@ class EditPreferencesBox extends Composite {
}
}
@UiHandler("cursorBlinkRate")
void onCursoBlinkRate(ValueChangeEvent<String> e) {
String v = e.getValue();
if (v != null && v.length() > 0) {
// A negative value hides the cursor entirely:
// don't let user shoot himself in the foot.
prefs.cursorBlinkRate(Math.max(0, Integer.parseInt(v)));
view.getEditor().setOption("cursorBlinkRate", prefs.cursorBlinkRate());
}
}
@UiHandler("topMenu")
void onTopMenu(ValueChangeEvent<Boolean> e) {
prefs.hideTopMenu(!e.getValue());

View File

@@ -181,6 +181,12 @@ limitations under the License.
visibleLength='4'
alignment='RIGHT'/></td>
</tr>
<tr>
<th><ui:msg>Cursor Blink Rate</ui:msg></th>
<td><x:NpIntTextBox ui:field='cursorBlinkRate'
visibleLength='4'
alignment='RIGHT'/></td>
</tr>
<tr>
<th><ui:msg>Top Menu</ui:msg></th>
<td><g:ToggleButton ui:field='topMenu'>

View File

@@ -441,7 +441,7 @@ public class EditScreen extends Screen {
cm = CodeMirror.create(editor, Configuration.create()
.set("value", content)
.set("readOnly", false)
.set("cursorBlinkRate", 0)
.set("cursorBlinkRate", prefs.cursorBlinkRate())
.set("cursorHeight", 0.85)
.set("lineNumbers", prefs.hideLineNumbers())
.set("tabSize", prefs.tabSize())