mirror of
https://github.com/discourse/discourse.git
synced 2025-02-16 18:24:52 -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');
|
$preview.off('scroll');
|
||||||
|
|
||||||
$input.on('scroll', () => {
|
$input.on('scroll', () => {
|
||||||
if (this.get('shouldBuildScrollMap')) {
|
this._syncScroll(this._syncEditorAndPreviewScroll, $input, $preview);
|
||||||
this.set('scrollMap', this._buildScrollMap($input, $preview));
|
|
||||||
this.set('shouldBuildScrollMap', false);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ember.run.throttle(this, this._syncEditorAndPreviewScroll, $input, $preview, this.get('scrollMap'), 20);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -154,16 +149,20 @@ export default Ember.Component.extend({
|
|||||||
$input.off('scroll');
|
$input.off('scroll');
|
||||||
|
|
||||||
$preview.on('scroll', () => {
|
$preview.on('scroll', () => {
|
||||||
if (this.get('shouldBuildScrollMap')) {
|
this._syncScroll(this._syncPreviewAndEditorScroll, $input, $preview);
|
||||||
this.set('scrollMap', this._buildScrollMap($input, $preview));
|
|
||||||
this.set('shouldBuildScrollMap', false);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ember.run.throttle(this, this._syncPreviewAndEditorScroll, $input, $preview, this.get('scrollMap'), 20);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_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() {
|
_teardownInputPreviewSync() {
|
||||||
[this.$('.d-editor-input'), this.$('.d-editor-preview')].forEach($element => {
|
[this.$('.d-editor-input'), this.$('.d-editor-preview')].forEach($element => {
|
||||||
$element.off("mouseenter touchstart");
|
$element.off("mouseenter touchstart");
|
||||||
|
@ -28,11 +28,12 @@ export function setup(helper) {
|
|||||||
helper.registerPlugin(md => {
|
helper.registerPlugin(md => {
|
||||||
const injectLineNumber = (tokens, index, options, env, self) => {
|
const injectLineNumber = (tokens, index, options, env, self) => {
|
||||||
let line;
|
let line;
|
||||||
|
const token = tokens[index];
|
||||||
|
|
||||||
if (tokens[index].map && tokens[index].level === 0) {
|
if (token.map && token.level === 0) {
|
||||||
line = tokens[index].map[0];
|
line = token.map[0];
|
||||||
tokens[index].attrJoin('class', 'preview-sync-line');
|
token.attrJoin('class', 'preview-sync-line');
|
||||||
tokens[index].attrSet('data-line-number', String(line));
|
token.attrSet('data-line-number', String(line));
|
||||||
}
|
}
|
||||||
|
|
||||||
return self.renderToken(tokens, index, options, env, self);
|
return self.renderToken(tokens, index, options, env, self);
|
||||||
|
Loading…
Reference in New Issue
Block a user