mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-24 17:36:14 -04:00
[fix] Ignore default line attribs when detecting edges of changeset (#3420)
When comparing original content with the changes made by the user, we need to ignore some line attribs that are added by content collector, otherwise we would consider the change started on the first char of the line -- the '*' that is added when line has line attribs. In order to be able to handle both #3354 and #3118, we need to take into account both the styles attribs (to fix #3354) and the line attribs defined by any of the plugins (to fix #3118), but we can ignore those extra line attribs that are added by Etherpad and do not add any functionality (`'lmkr', 'insertorder', 'start'`).
This commit is contained in:
parent
7729e5a1a9
commit
58c3154769
3 changed files with 117 additions and 8 deletions
|
@ -4,6 +4,10 @@ var _ = require('./underscore');
|
|||
|
||||
var lineMarkerAttribute = 'lmkr';
|
||||
|
||||
// Some of these attributes are kept for compatibility purposes.
|
||||
// Not sure if we need all of them
|
||||
var DEFAULT_LINE_ATTRIBUTES = ['author', 'lmkr', 'insertorder', 'start'];
|
||||
|
||||
// If one of these attributes are set to the first character of a
|
||||
// line it is considered as a line attribute marker i.e. attributes
|
||||
// set on this marker are applied to the whole line.
|
||||
|
@ -35,6 +39,7 @@ var AttributeManager = function(rep, applyChangesetCallback)
|
|||
// it will be considered as a line marker
|
||||
};
|
||||
|
||||
AttributeManager.DEFAULT_LINE_ATTRIBUTES = DEFAULT_LINE_ATTRIBUTES;
|
||||
AttributeManager.lineAttributes = lineAttributes;
|
||||
|
||||
AttributeManager.prototype = _(AttributeManager.prototype).extend({
|
||||
|
@ -375,7 +380,7 @@ AttributeManager.prototype = _(AttributeManager.prototype).extend({
|
|||
ChangesetUtils.buildKeepToStartOfRange(this.rep, builder, [lineNum, 0]);
|
||||
|
||||
var countAttribsWithMarker = _.chain(attribs).filter(function(a){return !!a[1];})
|
||||
.map(function(a){return a[0];}).difference(['author', 'lmkr', 'insertorder', 'start']).size().value();
|
||||
.map(function(a){return a[0];}).difference(DEFAULT_LINE_ATTRIBUTES).size().value();
|
||||
|
||||
//if we have marker and any of attributes don't need to have marker. we need delete it
|
||||
if(hasMarker && !countAttribsWithMarker){
|
||||
|
|
|
@ -1778,19 +1778,15 @@ function Ace2Inner(){
|
|||
strikethrough: true,
|
||||
list: true
|
||||
};
|
||||
var OTHER_INCORPED_ATTRIBS = {
|
||||
insertorder: true,
|
||||
author: true
|
||||
};
|
||||
|
||||
function isStyleAttribute(aname)
|
||||
{
|
||||
return !!STYLE_ATTRIBS[aname];
|
||||
}
|
||||
|
||||
function isOtherIncorpedAttribute(aname)
|
||||
function isDefaultLineAttribute(aname)
|
||||
{
|
||||
return !!OTHER_INCORPED_ATTRIBS[aname];
|
||||
return AttributeManager.DEFAULT_LINE_ATTRIBUTES.indexOf(aname) !== -1;
|
||||
}
|
||||
|
||||
function insertDomLines(nodeToAddAfter, infoStructs, isTimeUp)
|
||||
|
@ -2757,9 +2753,12 @@ function Ace2Inner(){
|
|||
|
||||
function analyzeChange(oldText, newText, oldAttribs, newAttribs, optSelStartHint, optSelEndHint)
|
||||
{
|
||||
// we need to take into account both the styles attributes & attributes defined by
|
||||
// the plugins, so basically we can ignore only the default line attribs used by
|
||||
// Etherpad
|
||||
function incorpedAttribFilter(anum)
|
||||
{
|
||||
return !isOtherIncorpedAttribute(rep.apool.getAttribKey(anum));
|
||||
return !isDefaultLineAttribute(rep.apool.getAttribKey(anum));
|
||||
}
|
||||
|
||||
function attribRuns(attribs)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue