much cleaner

getATtriuteOnSelection-extend
John McLear 2016-03-26 11:00:00 +08:00
parent 1d1354e212
commit add21368f9
2 changed files with 18 additions and 9 deletions

View File

@ -187,6 +187,17 @@ AttributeManager.prototype = _(AttributeManager.prototype).extend({
getAttributeOnSelection: function(attributeName, prevChar){
var rep = this.rep;
if (!(rep.selStart && rep.selEnd)) return
// If we're looking for the caret attribute not the selection
// has the user already got a selection or is this purely a caret location?
var isNotSelection = (rep.selStart[0] == rep.selEnd[0] && rep.selEnd[1] === rep.selStart[1]);
if(isNotSelection){
if(prevChar){
// If it's not the start of the line
if(rep.selStart[1] !== 0){
rep.selStart[1]--;
}
}
}
var withIt = Changeset.makeAttribsString('+', [
[attributeName, 'true']

View File

@ -2341,15 +2341,13 @@ function Ace2Inner(){
// prevChar tells the function if it needs to look at the previous character
function getAttributeOnSelection(attributeName, prevChar){
if (!(rep.selStart && rep.selEnd)) return
// If we're looking for the caret attribute not the selection
if(prevChar){
// If it's not the start of the line
if(rep.selStart[1] !== 0){
rep.selStart[1]--;
}else{
// It's the start of the line so look at the first character
rep.selEnd[1]++;
var isNotSelection = (rep.selStart[0] == rep.selEnd[0] && rep.selEnd[1] === rep.selStart[1]);
if(isNotSelection){
if(prevChar){
// If it's not the start of the line
if(rep.selStart[1] !== 0){
rep.selStart[1]--;
}
}
}