The problem seems to issue from RichTextCodeMirror.prototype.updateCurrentAttributes_, which is called continuously from RichTextCodeMirror.prototype.onCursorActivity_
The code always tries to pick up the attributes (getAnnotatedSpansForPos) of the previous character for the current character.
This makes sense when you enter a new character inside an annotated span (ie a bolded text), but not in our case.
What I tried was to modify the code so that if we are on the first character of the line, do not use any attributes of the line before..
So in RichTextCodeMirror.prototype.updateCurrentAttributes_
Instead of
} else {
// Back up before any newlines or line sentinels.
while(pos > 0) {
c = this.getRange(pos-1, pos);
if (c !== '\n' && c !== LineSentinelCharacter)
break;
pos--;
}
}
I did:
} else {
// Back up before any newlines or line sentinels.
c = this.getRange(pos-1, pos);
if (c=='\n' || c==LineSentinelCharacter) { // a new line always starts with no attributes
this.currentAttributes_ = {};
return;
}
while(pos > 0) {
c = this.getRange(pos-1, pos);
if (c !== '\n' && c !== LineSentinelCharacter)
break;
pos--;
}
}
This is not perfect at all. It means that you loose any formatting on a new line. So if for example you type in bold and then press new line, bold is automatically turned off. However it is much better as far as the original issue is- that is when starting to type in a new line you don't surprisingly get the style of the line before.
I would be very grateful if you can have a quick look at this and give any ideas into a more proper solution ?
Thx !