(1) add status bar to text mode
(2)add caret position to text mode status bar
This commit is contained in:
parent
22e99aa801
commit
ed030c0518
File diff suppressed because one or more lines are too long
|
@ -247,7 +247,6 @@ textmode.create = function (container, options) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.statusBar) {
|
if (options.statusBar) {
|
||||||
if (this.mode === 'code') {
|
|
||||||
util.addClassName(this.content, 'has-status-bar');
|
util.addClassName(this.content, 'has-status-bar');
|
||||||
|
|
||||||
this.curserInfoElements = {};
|
this.curserInfoElements = {};
|
||||||
|
@ -296,7 +295,6 @@ textmode.create = function (container, options) {
|
||||||
statusBar.appendChild(countVal);
|
statusBar.appendChild(countVal);
|
||||||
statusBar.appendChild(countLabel);
|
statusBar.appendChild(countLabel);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
this.setSchema(this.options.schema, this.options.schemaRefs);
|
this.setSchema(this.options.schema, this.options.schemaRefs);
|
||||||
};
|
};
|
||||||
|
@ -329,19 +327,7 @@ textmode._onChange = function () {
|
||||||
*/
|
*/
|
||||||
textmode._onSelect = function () {
|
textmode._onSelect = function () {
|
||||||
if(this.options.statusBar) {
|
if(this.options.statusBar) {
|
||||||
if (this.textarea) {
|
this._setCursorInfoDisplay();
|
||||||
var selectionRange = util.getInputSelection(this.textarea);
|
|
||||||
if (selectionRange.start !== selectionRange.end) {
|
|
||||||
this._setSelectionCountDisplay(Math.abs(selectionRange.end - selectionRange.start));
|
|
||||||
}
|
|
||||||
} else if (this.aceEditor && this.curserInfoElements) {
|
|
||||||
var curserPos = this.aceEditor.getCursorPosition();
|
|
||||||
var selectedText = this.aceEditor.getSelectedText();
|
|
||||||
|
|
||||||
this.curserInfoElements.lnVal.innerText = curserPos.row + 1;
|
|
||||||
this.curserInfoElements.colVal.innerText = curserPos.column + 1;
|
|
||||||
this._setSelectionCountDisplay(selectedText.length);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -371,7 +357,7 @@ textmode._onKeyDown = function (event) {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
}
|
}
|
||||||
|
|
||||||
this._setSelectionCountDisplay();
|
this._setCursorInfoDisplay();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -380,7 +366,7 @@ textmode._onKeyDown = function (event) {
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
textmode._onMouseDown = function (event) {
|
textmode._onMouseDown = function (event) {
|
||||||
this._setSelectionCountDisplay();
|
this._setCursorInfoDisplay();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -389,18 +375,46 @@ textmode._onMouseDown = function (event) {
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
textmode._onBlur = function (event) {
|
textmode._onBlur = function (event) {
|
||||||
this._setSelectionCountDisplay();
|
this._setCursorInfoDisplay();
|
||||||
};
|
};
|
||||||
|
|
||||||
textmode._setSelectionCountDisplay = function (value) {
|
/**
|
||||||
if (this.options.statusBar && this.curserInfoElements) {
|
* Update the status bar cursor info
|
||||||
if (value && this.curserInfoElements && this.curserInfoElements.countVal) {
|
*/
|
||||||
this.curserInfoElements.countVal.innerText = value;
|
textmode._setCursorInfoDisplay = function () {
|
||||||
this.curserInfoElements.countVal.style.display = 'inline';
|
if(this.options.statusBar) {
|
||||||
this.curserInfoElements.countLabel.style.display = 'inline';
|
var me = this;
|
||||||
} else {
|
var line, col, count;
|
||||||
this.curserInfoElements.countVal.style.display = 'none';
|
if (this.textarea) {
|
||||||
this.curserInfoElements.countLabel.style.display = 'none';
|
setTimeout(function() { //this to varify we get the most updated textarea cursor selection
|
||||||
|
var selectionRange = util.getInputSelection(me.textarea);
|
||||||
|
line = selectionRange.row;
|
||||||
|
col = selectionRange.col;
|
||||||
|
if (selectionRange.start !== selectionRange.end) {
|
||||||
|
count = selectionRange.end - selectionRange.start;
|
||||||
|
}
|
||||||
|
updateDisplay.apply(me);
|
||||||
|
},0);
|
||||||
|
|
||||||
|
} else if (this.aceEditor && this.curserInfoElements) {
|
||||||
|
var curserPos = this.aceEditor.getCursorPosition();
|
||||||
|
var selectedText = this.aceEditor.getSelectedText();
|
||||||
|
|
||||||
|
line = curserPos.row + 1;
|
||||||
|
col = curserPos.column + 1;
|
||||||
|
count = selectedText.length;
|
||||||
|
updateDisplay.apply(me);
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateDisplay() {
|
||||||
|
|
||||||
|
if (this.curserInfoElements.countVal.innerText !== count) {
|
||||||
|
this.curserInfoElements.countVal.innerText = count;
|
||||||
|
this.curserInfoElements.countVal.style.display = count ? 'inline' : 'none';
|
||||||
|
this.curserInfoElements.countLabel.style.display = count ? 'inline' : 'none';
|
||||||
|
}
|
||||||
|
this.curserInfoElements.lnVal.innerText = line;
|
||||||
|
this.curserInfoElements.colVal.innerText = col;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -863,9 +863,15 @@ exports.getInputSelection = function(el) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var textTillCaret = el.value.substring(0,end);
|
||||||
|
var row = (textTillCaret.match(/\n/g) || []).length + 1;
|
||||||
|
var col = textTillCaret.length - textTillCaret.lastIndexOf("\n");
|
||||||
|
|
||||||
return {
|
return {
|
||||||
start: start,
|
start: start,
|
||||||
end: end
|
end: end,
|
||||||
|
col: col,
|
||||||
|
row: row
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue