mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-02-01 03:12:42 +01:00
changesettracker: Plumb author ID to avoid global pad
variable
This commit is contained in:
parent
2dfb1c494b
commit
b9bea963e4
4 changed files with 11 additions and 5 deletions
|
@ -119,6 +119,7 @@ const Ace2Editor = function () {
|
||||||
'applyChangesToBase',
|
'applyChangesToBase',
|
||||||
'applyPreparedChangesetToBase',
|
'applyPreparedChangesetToBase',
|
||||||
'setUserChangeNotificationCallback',
|
'setUserChangeNotificationCallback',
|
||||||
|
'setAuthorId',
|
||||||
'setAuthorInfo',
|
'setAuthorInfo',
|
||||||
'callWithAce',
|
'callWithAce',
|
||||||
'execCommand',
|
'execCommand',
|
||||||
|
|
|
@ -684,6 +684,7 @@ function Ace2Inner(editorInfo, cssManagers) {
|
||||||
editorInfo.ace_setUserChangeNotificationCallback = (f) => {
|
editorInfo.ace_setUserChangeNotificationCallback = (f) => {
|
||||||
changesetTracker.setUserChangeNotificationCallback(f);
|
changesetTracker.setUserChangeNotificationCallback(f);
|
||||||
};
|
};
|
||||||
|
editorInfo.ace_setAuthorId = (authorId) => changesetTracker.setAuthorId(authorId);
|
||||||
editorInfo.ace_setAuthorInfo = (author, info) => {
|
editorInfo.ace_setAuthorInfo = (author, info) => {
|
||||||
setAuthorInfo(author, info);
|
setAuthorInfo(author, info);
|
||||||
};
|
};
|
||||||
|
|
|
@ -64,6 +64,10 @@ const makeChangesetTracker = (scheduler, apool, aceCallbacksProvider) => {
|
||||||
|
|
||||||
let self;
|
let self;
|
||||||
return self = {
|
return self = {
|
||||||
|
_authorId: null,
|
||||||
|
setAuthorId(authorId) {
|
||||||
|
this._authorId = authorId;
|
||||||
|
},
|
||||||
isTracking: () => tracking,
|
isTracking: () => tracking,
|
||||||
setBaseText: (text) => {
|
setBaseText: (text) => {
|
||||||
self.setBaseAttributedText(Changeset.makeAText(text), null);
|
self.setBaseAttributedText(Changeset.makeAText(text), null);
|
||||||
|
@ -128,7 +132,7 @@ const makeChangesetTracker = (scheduler, apool, aceCallbacksProvider) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
prepareUserChangeset: () => {
|
prepareUserChangeset() {
|
||||||
// If there are user changes to submit, 'changeset' will be the
|
// If there are user changes to submit, 'changeset' will be the
|
||||||
// changeset, else it will be null.
|
// changeset, else it will be null.
|
||||||
let toSubmit;
|
let toSubmit;
|
||||||
|
@ -137,8 +141,7 @@ const makeChangesetTracker = (scheduler, apool, aceCallbacksProvider) => {
|
||||||
// that includes old submittedChangeset
|
// that includes old submittedChangeset
|
||||||
toSubmit = Changeset.compose(submittedChangeset, userChangeset, apool);
|
toSubmit = Changeset.compose(submittedChangeset, userChangeset, apool);
|
||||||
} else {
|
} else {
|
||||||
// Get my authorID
|
if (!this._authorId) throw new Error('setAuthorId() not yet called');
|
||||||
const authorId = parent.parent.pad.myUserInfo.userId;
|
|
||||||
|
|
||||||
// Sanitize authorship: Replace all author attributes with this user's author ID in case the
|
// Sanitize authorship: Replace all author attributes with this user's author ID in case the
|
||||||
// text was copied from another author.
|
// text was copied from another author.
|
||||||
|
@ -149,8 +152,8 @@ const makeChangesetTracker = (scheduler, apool, aceCallbacksProvider) => {
|
||||||
if (op.opcode === '+') {
|
if (op.opcode === '+') {
|
||||||
const attribs = AttributeMap.fromString(op.attribs, apool);
|
const attribs = AttributeMap.fromString(op.attribs, apool);
|
||||||
const oldAuthorId = attribs.get('author');
|
const oldAuthorId = attribs.get('author');
|
||||||
if (oldAuthorId != null && oldAuthorId !== authorId) {
|
if (oldAuthorId != null && oldAuthorId !== this._authorId) {
|
||||||
attribs.set('author', authorId);
|
attribs.set('author', this._authorId);
|
||||||
op.attribs = attribs.toString();
|
op.attribs = attribs.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -408,6 +408,7 @@ const pad = {
|
||||||
};
|
};
|
||||||
|
|
||||||
const postAceInit = () => {
|
const postAceInit = () => {
|
||||||
|
padeditor.ace.setAuthorId(clientVars.userId);
|
||||||
padeditbar.init();
|
padeditbar.init();
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
padeditor.ace.focus();
|
padeditor.ace.focus();
|
||||||
|
|
Loading…
Reference in a new issue