1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-10-23 17:18:51 +02:00
phorge-phorge/webroot/rsrc/js/application/diff/DiffInlineContentState.js
epriestley cb00cb99e2 Make client inlines track an "active" state
Summary:
Ref T13559. Rather than reading from the document, make client inlines actively track their current "active" state.

The "active" state is what the user currently sees in the client UI.

Test Plan: Created inlines, etc. See followups.

Maniphest Tasks: T13559

Differential Revision: https://secure.phabricator.com/D21646
2021-03-29 09:00:24 -07:00

71 lines
1.4 KiB
JavaScript

/**
* @provides phabricator-diff-inline-content-state
* @requires javelin-dom
* @javelin
*/
JX.install('DiffInlineContentState', {
construct : function() {
},
properties: {
text: null,
suggestionText: null,
hasSuggestion: false
},
members: {
readForm: function(row) {
var node;
try {
node = JX.DOM.find(row, 'textarea', 'inline-content-text');
this.setText(node.value);
} catch (ex) {
this.setText(null);
}
node = this._getSuggestionNode(row);
if (node) {
this.setSuggestionText(node.value);
} else {
this.setSuggestionText(null);
}
return this;
},
getWireFormat: function() {
return {
text: this.getText(),
suggestionText: this.getSuggestionText(),
hasSuggestion: this.getHasSuggestion()
};
},
readWireFormat: function(map) {
this.setText(map.text || null);
this.setSuggestionText(map.suggestionText || null);
this.setHasSuggestion(!!map.hasSuggestion);
return this;
},
getTextForQuote: function() {
var text = this.getText();
text = '> ' + text.replace(/\n/g, '\n> ') + '\n\n';
return text;
},
_getSuggestionNode: function(row) {
try {
return JX.DOM.find(row, 'textarea', 'inline-content-suggestion');
} catch (ex) {
return null;
}
}
}
});