mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 02:40:53 -06:00
REFACTORY: Dry up some composer syncing code.
This commit is contained in:
parent
e0e99d4bbd
commit
44333c5de3
@ -141,12 +141,7 @@ export default Ember.Component.extend({
|
||||
$preview.off('scroll');
|
||||
|
||||
$input.on('scroll', () => {
|
||||
if (this.get('shouldBuildScrollMap')) {
|
||||
this.set('scrollMap', this._buildScrollMap($input, $preview));
|
||||
this.set('shouldBuildScrollMap', false);
|
||||
}
|
||||
|
||||
Ember.run.throttle(this, this._syncEditorAndPreviewScroll, $input, $preview, this.get('scrollMap'), 20);
|
||||
this._syncScroll(this._syncEditorAndPreviewScroll, $input, $preview);
|
||||
});
|
||||
});
|
||||
|
||||
@ -154,16 +149,20 @@ export default Ember.Component.extend({
|
||||
$input.off('scroll');
|
||||
|
||||
$preview.on('scroll', () => {
|
||||
if (this.get('shouldBuildScrollMap')) {
|
||||
this.set('scrollMap', this._buildScrollMap($input, $preview));
|
||||
this.set('shouldBuildScrollMap', false);
|
||||
}
|
||||
|
||||
Ember.run.throttle(this, this._syncPreviewAndEditorScroll, $input, $preview, this.get('scrollMap'), 20);
|
||||
this._syncScroll(this._syncPreviewAndEditorScroll, $input, $preview);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
_syncScroll($callback, $input, $preview) {
|
||||
if (!this.get('scrollMap') || this.get('shouldBuildScrollMap')) {
|
||||
this.set('scrollMap', this._buildScrollMap($input, $preview));
|
||||
this.set('shouldBuildScrollMap', false);
|
||||
}
|
||||
|
||||
Ember.run.throttle(this, $callback, $input, $preview, this.get('scrollMap'), 20);
|
||||
},
|
||||
|
||||
_teardownInputPreviewSync() {
|
||||
[this.$('.d-editor-input'), this.$('.d-editor-preview')].forEach($element => {
|
||||
$element.off("mouseenter touchstart");
|
||||
|
@ -28,11 +28,12 @@ export function setup(helper) {
|
||||
helper.registerPlugin(md => {
|
||||
const injectLineNumber = (tokens, index, options, env, self) => {
|
||||
let line;
|
||||
const token = tokens[index];
|
||||
|
||||
if (tokens[index].map && tokens[index].level === 0) {
|
||||
line = tokens[index].map[0];
|
||||
tokens[index].attrJoin('class', 'preview-sync-line');
|
||||
tokens[index].attrSet('data-line-number', String(line));
|
||||
if (token.map && token.level === 0) {
|
||||
line = token.map[0];
|
||||
token.attrJoin('class', 'preview-sync-line');
|
||||
token.attrSet('data-line-number', String(line));
|
||||
}
|
||||
|
||||
return self.renderToken(tokens, index, options, env, self);
|
||||
|
Loading…
Reference in New Issue
Block a user