mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-01-31 19:02:59 +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',
|
||||
'applyPreparedChangesetToBase',
|
||||
'setUserChangeNotificationCallback',
|
||||
'setAuthorId',
|
||||
'setAuthorInfo',
|
||||
'callWithAce',
|
||||
'execCommand',
|
||||
|
|
|
@ -684,6 +684,7 @@ function Ace2Inner(editorInfo, cssManagers) {
|
|||
editorInfo.ace_setUserChangeNotificationCallback = (f) => {
|
||||
changesetTracker.setUserChangeNotificationCallback(f);
|
||||
};
|
||||
editorInfo.ace_setAuthorId = (authorId) => changesetTracker.setAuthorId(authorId);
|
||||
editorInfo.ace_setAuthorInfo = (author, info) => {
|
||||
setAuthorInfo(author, info);
|
||||
};
|
||||
|
|
|
@ -64,6 +64,10 @@ const makeChangesetTracker = (scheduler, apool, aceCallbacksProvider) => {
|
|||
|
||||
let self;
|
||||
return self = {
|
||||
_authorId: null,
|
||||
setAuthorId(authorId) {
|
||||
this._authorId = authorId;
|
||||
},
|
||||
isTracking: () => tracking,
|
||||
setBaseText: (text) => {
|
||||
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
|
||||
// changeset, else it will be null.
|
||||
let toSubmit;
|
||||
|
@ -137,8 +141,7 @@ const makeChangesetTracker = (scheduler, apool, aceCallbacksProvider) => {
|
|||
// that includes old submittedChangeset
|
||||
toSubmit = Changeset.compose(submittedChangeset, userChangeset, apool);
|
||||
} else {
|
||||
// Get my authorID
|
||||
const authorId = parent.parent.pad.myUserInfo.userId;
|
||||
if (!this._authorId) throw new Error('setAuthorId() not yet called');
|
||||
|
||||
// Sanitize authorship: Replace all author attributes with this user's author ID in case the
|
||||
// text was copied from another author.
|
||||
|
@ -149,8 +152,8 @@ const makeChangesetTracker = (scheduler, apool, aceCallbacksProvider) => {
|
|||
if (op.opcode === '+') {
|
||||
const attribs = AttributeMap.fromString(op.attribs, apool);
|
||||
const oldAuthorId = attribs.get('author');
|
||||
if (oldAuthorId != null && oldAuthorId !== authorId) {
|
||||
attribs.set('author', authorId);
|
||||
if (oldAuthorId != null && oldAuthorId !== this._authorId) {
|
||||
attribs.set('author', this._authorId);
|
||||
op.attribs = attribs.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -408,6 +408,7 @@ const pad = {
|
|||
};
|
||||
|
||||
const postAceInit = () => {
|
||||
padeditor.ace.setAuthorId(clientVars.userId);
|
||||
padeditbar.init();
|
||||
setTimeout(() => {
|
||||
padeditor.ace.focus();
|
||||
|
|
Loading…
Reference in a new issue