Skip to content

Commit

Permalink
refactor: scrollfollow -> scrollsync (#1052)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyuwoo.choi committed Dec 21, 2017
1 parent 3de2032 commit 827e413
Show file tree
Hide file tree
Showing 14 changed files with 82 additions and 82 deletions.
2 changes: 1 addition & 1 deletion demo/demo-dev.html
Expand Up @@ -41,7 +41,7 @@
height: '100%',
initialEditType: 'wysiwyg',
useCommandShortcut: true,
exts: ['scrollFollow', 'colorSyntax', 'uml', 'chart', 'mark', 'table', 'taskCounter']
exts: ['scrollSync', 'colorSyntax', 'uml', 'chart', 'mark', 'table', 'taskCounter']
});
</script>
</body>
Expand Down
4 changes: 2 additions & 2 deletions demo/demo-scrollfollow.html → demo/demo-scrollsync.html
Expand Up @@ -31,13 +31,13 @@
<body>
<div id="editSection"></div>
<script src="../dist/tui-editor-Editor.js"></script>
<script src="../dist/tui-editor-extScrollFollow.js"></script>
<script src="../dist/tui-editor-extScrollSync.js"></script>
<script>
$('#editSection').tuiEditor({
previewStyle: 'vertical',
height: '400px',
initialEditType: 'wysiwyg',
exts: ['scrollFollow']
exts: ['scrollSync']
});
</script>
</body>
Expand Down
2 changes: 1 addition & 1 deletion demo/demo-uml-viewer.html
Expand Up @@ -60,7 +60,7 @@
].join('\n');
$('#editSection').tuiEditorViewer({
initialValue: content,
exts: ['scrollFollow', {
exts: ['scrollSync', {
name: 'uml', // enable plant uml plugin
rendererURL: 'http://www.plantuml.com/plantuml/png/'
}]
Expand Down
18 changes: 9 additions & 9 deletions src/css/tui-editor.css
Expand Up @@ -300,22 +300,22 @@
margin-right: 0;
}

.tui-editor-defaultUI-toolbar button.tui-scrollfollow {
.tui-editor-defaultUI-toolbar button.tui-scrollsync {
width: auto;
color: #777777;
border: 0;
}

.tui-editor-defaultUI button.tui-scrollfollow:after {
.tui-editor-defaultUI button.tui-scrollsync:after {
content: "Scroll off";
}

.tui-editor-defaultUI button.tui-scrollfollow.active {
.tui-editor-defaultUI button.tui-scrollsync.active {
color: #125de6;
font-weight: bold;
}

.tui-editor-defaultUI button.tui-scrollfollow.active:after {
.tui-editor-defaultUI button.tui-scrollsync.active:after {
content: "Scroll on";
}

Expand Down Expand Up @@ -1112,16 +1112,16 @@
overflow-y: auto;
}

.tui-split-scroll button.tui-scrollfollow {
.tui-split-scroll button.tui-scrollsync {
top: 10px;
opacity: 0.2;
}

.tui-split-scroll button.tui-scrollfollow::after {
.tui-split-scroll button.tui-scrollsync::after {
content: "scroll off";
}

.tui-split-scroll.scroll-sync button.tui-scrollfollow {
.tui-split-scroll.scroll-sync button.tui-scrollsync {
opacity: 0.5;
}

Expand All @@ -1131,7 +1131,7 @@
overflow: initial;
}

.tui-split-scroll.scroll-sync button.tui-scrollfollow::after {
.tui-split-scroll.scroll-sync button.tui-scrollsync::after {
content: "scroll on";
}

Expand All @@ -1151,7 +1151,7 @@
display: none;
}

.tui-split-scroll.single-content button.tui-scrollfollow {
.tui-split-scroll.single-content button.tui-scrollsync {
display: none;
}

Expand Down
36 changes: 18 additions & 18 deletions src/js/codemirror/markdown.js
Expand Up @@ -35,7 +35,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
modeCfg.underscoresBreakWords = true;

// TUI.EDITOR MODIFICATION START
// scrollFollow prototype
// scrollSync prototype
// https://github.nhnent.com/fe/tui.editor/commit/f63d6ae79078923d369e6c170d07485f05c42fd7
// Use `fencedCodeBlocks` to configure fenced code blocks. false to
// disable, string to specify a precise regexp that the fence should
Expand Down Expand Up @@ -76,7 +76,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
, olRE = /^[0-9]+([.)])\s+/
, taskListRE = /^\[(x| )\](?=\s)/ // Must follow ulRE or olRE
// TUI.EDITOR MODIFICATION START
// scrollFollow prototype
// scrollSync prototype
// https://github.nhnent.com/fe/tui.editor/commit/f63d6ae79078923d369e6c170d07485f05c42fd7
, atxHeaderRE = modeCfg.allowAtxHeaderWithoutSpace ? /^(#+)/ : /^(#+)(?: |$)/
, setextHeaderRE = /^ *(?:\={1,}|-{1,})\s*$/
Expand All @@ -99,7 +99,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
}

// TUI.EDITOR MODIFICATION START
// scrollFollow prototype
// scrollSync prototype
// https://github.nhnent.com/fe/tui.editor/commit/f63d6ae79078923d369e6c170d07485f05c42fd7
function lineIsEmpty(line) {
return !line || !/\S/.test(line.string)
Expand Down Expand Up @@ -129,7 +129,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
state.trailingSpace = 0;
state.trailingSpaceNewLine = false;
// TUI.EDITOR MODIFICATION START
// scrollFollow prototype
// scrollSync prototype
// https://github.nhnent.com/fe/tui.editor/commit/f63d6ae79078923d369e6c170d07485f05c42fd7
// Mark this line as blank
state.prevLine = state.thisLine
Expand Down Expand Up @@ -176,7 +176,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
if (state.indentationDiff >= 4) {
stream.skipToEnd();
// TUI.EDITOR MODIFICATION START
// scrollFollow prototype
// scrollSync prototype
// https://github.nhnent.com/fe/tui.editor/commit/f63d6ae79078923d369e6c170d07485f05c42fd7
if (prevLineIsIndentedCode || lineIsEmpty(state.prevLine)) {
// if (prevLineIsIndentedCode || !state.prevLineHasContent) {
Expand All @@ -195,7 +195,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
state.f = state.inline;
return getType(state);
// TUI.EDITOR MODIFICATION START
// scrollFollow prototype
// scrollSync prototype
// https://github.nhnent.com/fe/tui.editor/commit/f63d6ae79078923d369e6c170d07485f05c42fd7
} else if (!lineIsEmpty(state.prevLine) && !state.quote && !prevLineIsList &&
!prevLineIsIndentedCode && (match = stream.match(setextHeaderRE))) {
Expand All @@ -216,7 +216,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
state.hr = true;
return hr;
// TUI.EDITOR MODIFICATION START
// scrollFollow prototype
// scrollSync prototype
// https://github.nhnent.com/fe/tui.editor/commit/f63d6ae79078923d369e6c170d07485f05c42fd7
} else if ((lineIsEmpty(state.prevLine) || prevLineIsList) && (stream.match(ulRE, false) || stream.match(olRE, false))) {
// } else if ((!state.prevLineHasContent || prevLineIsList) && (stream.match(ulRE, false) || stream.match(olRE, false))) {
Expand All @@ -229,7 +229,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
listType = 'ol';
}
// TUI.EDITOR MODIFICATION START
// scrollFollow prototype
// scrollSync prototype
// https://github.nhnent.com/fe/tui.editor/commit/f63d6ae79078923d369e6c170d07485f05c42fd7
// Roll back to original #1002
// https://github.nhnent.com/fe/tui.editor/issues/1002
Expand All @@ -250,7 +250,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
if (modeCfg.highlightFormatting) state.formatting = ["list", "list-" + listType];
return getType(state);
// TUI.EDITOR MODIFICATION START
// scrollFollow prototype
// scrollSync prototype
// https://github.nhnent.com/fe/tui.editor/commit/f63d6ae79078923d369e6c170d07485f05c42fd7
} else if (modeCfg.fencedCodeBlocks && (match = stream.match(fencedCodeRE, true))) {
state.fencedChars = match[1]
Expand Down Expand Up @@ -284,7 +284,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {

function local(stream, state) {
// TUI.EDITOR MODIFICATION START
// scrollFollow prototype
// scrollSync prototype
// https://github.nhnent.com/fe/tui.editor/commit/f63d6ae79078923d369e6c170d07485f05c42fd7
if (stream.sol() && state.fencedChars && stream.match(state.fencedChars, false)) {
// if (stream.sol() && stream.match("```", false)) {
Expand All @@ -302,7 +302,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {

function leavingLocal(stream, state) {
// TUI.EDITOR MODIFICATION START
// scrollFollow prototype
// scrollSync prototype
// https://github.nhnent.com/fe/tui.editor/commit/f63d6ae79078923d369e6c170d07485f05c42fd7
stream.match(state.fencedChars);
state.block = blockNormal;
Expand Down Expand Up @@ -750,7 +750,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
return {
f: blockNormal,
// TUI.EDITOR MODIFICATION START
// scrollFollow prototype
// scrollSync prototype
// https://github.nhnent.com/fe/tui.editor/commit/f63d6ae79078923d369e6c170d07485f05c42fd7
prevLine: null,
thisLine: null,
Expand Down Expand Up @@ -786,7 +786,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
trailingSpaceNewLine: false,
strikethrough: false,
// TUI.EDITOR MODIFICATION START
// scrollFollow prototype
// scrollSync prototype
// https://github.nhnent.com/fe/tui.editor/commit/f63d6ae79078923d369e6c170d07485f05c42fd7
fencedChars: null
// TUI.EDITOR MODIFICATION END
Expand All @@ -798,7 +798,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
f: s.f,

// TUI.EDITOR MODIFICATION START
// scrollFollow prototype
// scrollSync prototype
// https://github.nhnent.com/fe/tui.editor/commit/f63d6ae79078923d369e6c170d07485f05c42fd7
prevLine: s.prevLine,
thisLine: s.this,
Expand All @@ -818,7 +818,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
formatting: false,
linkTitle: s.linkTitle,
// TUI.EDITOR MODIFICATION START
// scrollFollow prototype
// scrollSync prototype
// https://github.nhnent.com/fe/tui.editor/commit/f63d6ae79078923d369e6c170d07485f05c42fd7
code: s.code,
// TUI.EDITOR MODIFICATION END
Expand All @@ -841,7 +841,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
trailingSpaceNewLine: s.trailingSpaceNewLine,
md_inside: s.md_inside,
// TUI.EDITOR MODIFICATION START
// scrollFollow prototype
// scrollSync prototype
// https://github.nhnent.com/fe/tui.editor/commit/f63d6ae79078923d369e6c170d07485f05c42fd7
fencedChars: s.fencedChars
// TUI.EDITOR MODIFICATION END
Expand All @@ -854,7 +854,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
state.formatting = false;

// TUI.EDITOR MODIFICATION START
// scrollFollow prototype
// scrollSync prototype
// https://github.nhnent.com/fe/tui.editor/commit/f63d6ae79078923d369e6c170d07485f05c42fd7
if (stream != state.thisLine) {
var forceBlankLine = state.header || state.hr;
Expand All @@ -868,7 +868,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {

if (stream.match(/^\s*$/, true) || forceBlankLine) {
// TUI.EDITOR MODIFICATION START
// scrollFollow prototype
// scrollSync prototype
// https://github.nhnent.com/fe/tui.editor/commit/f63d6ae79078923d369e6c170d07485f05c42fd7
blankLine(state);
if (!forceBlankLine) return null
Expand Down
@@ -1,5 +1,5 @@
/**
* @fileoverview Implements Scroll Follow Extension ScrollSync Module
* @fileoverview Implements Scroll Follow Extension ScrollManager Module
* @author Sungho Kim(sungho-kim@nhnent.com) FE Development Team/NHN Ent.
*/
import util from 'tui-code-snippet';
Expand All @@ -9,16 +9,16 @@ const SCROLL_TOP_PADDING = 20;
const SCROLL_BOCKING_RESET_DELAY = 15;

/**
* Class ScrollSync
* Class ScrollManager
* manage scroll sync between markdown editor and preview
*/
class ScrollSync {
class ScrollManager {
/**
* Creates an instance of ScrollSync.
* Creates an instance of ScrollManager.
* @param {SectionManager} sectionManager - sectionManager
* @param {CodeMirror} cm - CodeMirror
* @param {jQuery} $previewContainerEl - preview container
* @memberof ScrollSync
* @memberof ScrollManager
*/
constructor(sectionManager, cm, $previewContainerEl) {
this.sectionManager = sectionManager;
Expand Down Expand Up @@ -327,7 +327,7 @@ class ScrollSync {

/**
* Save Codemirror's scrollInfo for alternative use
* memberOf ScrollSync
* memberOf ScrollManager
*/
saveScrollInfo() {
this._savedScrollInfo = this.cm.getScrollInfo();
Expand All @@ -351,4 +351,4 @@ class ScrollSync {
}
}

export default ScrollSync;
export default ScrollManager;
Expand Up @@ -4,13 +4,13 @@
*/
import $ from 'jquery';
import Editor from '../editor';
import ScrollSync from './scrollSync';
import ScrollManager from './scrollManager';
import SectionManager from './sectionManager';

const {Button} = Editor;

function scrollFollowExtension(editor) {
const className = 'tui-scrollfollow';
function scrollSyncExtension(editor) {
const className = 'tui-scrollsync';
const i18n = editor.i18n;
const TOOL_TIP = {
active: i18n.get('Auto scroll enabled'),
Expand All @@ -23,7 +23,7 @@ function scrollFollowExtension(editor) {

const cm = editor.getCodeMirror();
const sectionManager = new SectionManager(cm, editor.preview);
const scrollSync = new ScrollSync(sectionManager, cm, editor.preview.$el);
const scrollManager = new ScrollManager(sectionManager, cm, editor.preview.$el);

let isScrollable = false;
let isActive = true;
Expand All @@ -35,7 +35,7 @@ function scrollFollowExtension(editor) {
// init button
button = new Button({
className,
command: 'scrollFollowToggle',
command: 'scrollSyncToggle',
tooltip: TOOL_TIP.active,
$el: $(`<button class="active ${className}" type="button"></button>`)
});
Expand All @@ -50,7 +50,7 @@ function scrollFollowExtension(editor) {

// Commands
editor.addCommand('markdown', {
name: 'scrollFollowToggle',
name: 'scrollSyncToggle',
exec() {
isActive = !isActive;
button._onOut();
Expand Down Expand Up @@ -87,7 +87,7 @@ function scrollFollowExtension(editor) {

editor.on('previewRenderAfter', () => {
sectionManager.sectionMatch();
scrollSync.syncPreviewScrollTopToMarkdown();
scrollManager.syncPreviewScrollTopToMarkdown();
isScrollable = true;
});

Expand All @@ -97,17 +97,17 @@ function scrollFollowExtension(editor) {
}

if (isScrollable && editor.preview.isVisible()) {
if (event.source === 'markdown' && !scrollSync.isMarkdownScrollEventBlocked) {
scrollSync.syncPreviewScrollTopToMarkdown();
} else if (event.source === 'preview' && !scrollSync.isPreviewScrollEventBlocked) {
scrollSync.syncMarkdownScrollTopToPreview();
if (event.source === 'markdown' && !scrollManager.isMarkdownScrollEventBlocked) {
scrollManager.syncPreviewScrollTopToMarkdown();
} else if (event.source === 'preview' && !scrollManager.isPreviewScrollEventBlocked) {
scrollManager.syncMarkdownScrollTopToPreview();
}
} else {
scrollSync.saveScrollInfo();
scrollManager.saveScrollInfo();
}
});
}

Editor.defineExtension('scrollFollow', scrollFollowExtension);
Editor.defineExtension('scrollSync', scrollSyncExtension);

export default scrollFollowExtension;
export default scrollSyncExtension;
2 changes: 1 addition & 1 deletion src/js/indexAll.js
Expand Up @@ -2,7 +2,7 @@ const Editor = require('./index');

import './extensions/chart/chart';
import './extensions/mark/mark';
import './extensions/scrollFollow/scrollFollow';
import './extensions/scrollSync/scrollSync';
import './extensions/table/table';
import './extensions/colorSyntax';
import './extensions/taskCounter';
Expand Down

0 comments on commit 827e413

Please sign in to comment.