Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
d5b331b7
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d5b331b7
编写于
6月 06, 2016
作者:
P
Phil Hughes
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improved design
Updated JS to remove undo manager - instead let the browser handle it all
上级
14d08d14
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
43 addition
and
105 deletion
+43
-105
app/assets/javascripts/lib/text_utility.js.coffee
app/assets/javascripts/lib/text_utility.js.coffee
+43
-105
未找到文件。
app/assets/javascripts/lib/text_utility.js.coffee
浏览文件 @
d5b331b7
((
w
)
->
w
.
gl
?=
{}
w
.
gl
.
text
?=
{}
w
.
gl
.
text
.
undoManager
?=
{}
gl
.
text
.
randomString
=
->
Math
.
random
().
toString
(
36
).
substring
(
7
)
gl
.
text
.
replaceRange
=
(
s
,
start
,
end
,
substitute
)
->
s
.
substring
(
0
,
start
)
+
substitute
+
s
.
substring
(
end
);
gl
.
text
.
wrap
=
(
textArea
,
tag
)
->
$textArea
=
$
(
textArea
)
oldVal
=
$textArea
.
val
()
$textArea
.
focus
()
textArea
=
$textArea
.
get
(
0
)
selObj
=
window
.
getSelection
()
selRange
=
selObj
.
getRangeAt
(
0
)
text
=
$textArea
.
val
()
replaceWith
=
@
replaceRange
(
text
,
textArea
.
selectionStart
,
textArea
.
selectionEnd
,
(
tag
+
selObj
.
toString
()
+
tag
))
$textArea
.
data
(
'old-val'
,
text
).
val
(
replaceWith
)
gl
.
text
.
undoManager
.
addUndo
(
oldVal
,
$textArea
.
val
())
gl
.
text
.
selectedText
=
(
text
,
textarea
)
->
text
.
substring
(
textarea
.
selectionStart
,
textarea
.
selectionEnd
)
gl
.
text
.
prepend
=
(
textArea
,
tag
)
->
$textArea
=
$
(
textArea
)
oldVal
=
$textArea
.
val
()
$textArea
.
focus
()
textArea
=
$textArea
.
get
(
0
)
selObj
=
window
.
getSelection
()
selRange
=
selObj
.
getRangeAt
(
0
)
text
=
$textArea
.
val
()
if
textArea
.
selectionStart
>
0
lineBreak
=
'
\n
'
gl
.
text
.
insertText
=
(
textArea
,
text
,
tag
,
selected
,
wrap
)
->
startChar
=
if
not
wrap
and
textArea
.
selectionStart
>
0
then
'
\n
'
else
''
insertText
=
"
#{
startChar
}#{
tag
}#{
selected
}#{
if
wrap
then
tag
else
' '
}
"
if
document
.
queryCommandSupported
(
'insertText'
)
document
.
execCommand
'insertText'
,
false
,
insertText
else
lineBreak
=
''
try
document
.
execCommand
(
"ms-beginUndoUnit"
)
replaceWith
=
@
replaceRange
(
text
,
textArea
.
selectionStart
,
textArea
.
selectionEnd
,
(
"
#{
lineBreak
}#{
tag
}#{
selObj
.
toString
()
}
\n
"
)
)
$textArea
.
data
(
'old-val'
,
text
).
val
(
replaceWith
);
gl
.
text
.
undoManager
.
addUndo
(
oldVal
,
$textArea
.
val
())
textArea
.
value
=
@
replaceRange
(
text
,
textArea
.
selectionStart
,
textArea
.
selectionEnd
,
insertText
)
try
document
.
execCommand
(
"ms-endUndoUnit"
)
gl
.
text
.
undoManager
.
history
=
{}
gl
.
text
.
undoManager
.
undoHistory
=
{}
@
moveCursor
(
textArea
,
tag
,
wrap
)
gl
.
text
.
undoManager
.
addUniqueIfNotExists
=
(
$ta
)
->
unique
=
$ta
.
attr
(
'data-unique'
)
if
not
unique
?
unique
=
gl
.
text
.
randomString
()
$ta
.
attr
(
'data-unique'
,
unique
)
gl
.
text
.
undoManager
.
history
[
unique
]
=
[]
gl
.
text
.
undoManager
.
undoHistory
[
unique
]
=
[]
unique
gl
.
text
.
moveCursor
=
(
textArea
,
tag
,
wrapped
)
->
return
unless
textArea
.
setSelectionRange
gl
.
text
.
undoManager
.
addUndo
=
(
oldVal
,
newVal
)
->
$thisTextarea
=
$
(
'textarea:focus'
)
unique
=
gl
.
text
.
undoManager
.
addUniqueIfNotExists
(
$thisTextarea
)
gl
.
text
.
undoManager
.
history
[
unique
].
push
({
oldVal
:
oldVal
,
newVal
:
newVal
})
if
textArea
.
selectionStart
is
textArea
.
selectionEnd
if
wrapped
pos
=
textArea
.
selectionStart
-
tag
.
length
else
pos
=
textArea
.
selectionStart
textArea
.
setSelectionRange
pos
,
pos
gl
.
text
.
undoManager
.
undo
=
()
->
$thisTextarea
=
$
(
'textarea:focus'
)
unique
=
gl
.
text
.
undoManager
.
addUniqueIfNotExists
(
$thisTextarea
)
if
not
gl
.
text
.
undoManager
.
history
[
unique
].
length
return
latestChange
=
gl
.
text
.
undoManager
.
history
[
unique
].
pop
()
gl
.
text
.
undoManager
.
undoHistory
[
unique
].
push
(
latestChange
)
$thisTextarea
.
val
(
latestChange
.
oldVal
)
gl
.
text
.
updateText
=
(
textArea
,
tag
,
wrap
)
->
$textArea
=
$
(
textArea
)
oldVal
=
$textArea
.
val
()
textArea
=
$textArea
.
get
(
0
)
text
=
$textArea
.
val
()
selected
=
@
selectedText
(
text
,
textArea
)
$textArea
.
focus
()
gl
.
text
.
undoManager
.
redo
=
()
->
$thisTextarea
=
$
(
'textarea:focus'
)
unique
=
gl
.
text
.
undoManager
.
addUniqueIfNotExists
(
$thisTextarea
)
if
not
gl
.
text
.
undoManager
.
undoHistory
[
unique
].
length
return
latestUndo
=
gl
.
text
.
undoManager
.
undoHistory
[
unique
].
pop
()
gl
.
text
.
undoManager
.
history
[
unique
].
push
(
latestUndo
)
$thisTextarea
.
val
(
latestUndo
.
newVal
)
@
insertText
(
textArea
,
text
,
tag
,
selected
,
wrap
)
gl
.
text
.
addListeners
=
()
->
gl
.
text
.
addListeners
=
->
self
=
@
$
(
'.js-md'
).
on
'click'
,
->
$this
=
$
(
@
)
if
$this
.
data
(
'md-wrap'
)
?
self
.
wrap
(
$this
.
closest
(
'.md-area'
).
find
(
'textarea'
),
$this
.
data
(
'md-tag'
)
)
else
if
$this
.
data
(
'md-prepend'
)
?
self
.
prepend
(
$this
.
closest
(
'.md-area'
).
find
(
'textarea'
),
$this
.
data
(
'md-tag'
)
)
else
self
.
wrap
(
$this
.
closest
(
'.md-area'
).
find
(
'textarea'
),
$this
.
data
(
'md-tag'
)
)
gl
.
text
.
_previousState
=
null
$
(
window
).
on
'keydown'
,
(
e
)
=>
$thisTextarea
=
$
(
'textarea:focus'
)
if
e
.
ctrlKey
or
e
.
metaKey
if
String
.
fromCharCode
(
e
.
which
).
toLowerCase
()
is
'z'
and
!
e
.
shiftKey
e
.
preventDefault
()
self
.
undoManager
.
undo
()
else
if
((
String
.
fromCharCode
(
e
.
which
).
toLowerCase
()
is
'z'
and
e
.
shiftKey
)
or
(
String
.
fromCharCode
(
e
.
which
).
toLowerCase
()
is
'y'
))
e
.
preventDefault
()
self
.
undoManager
.
redo
()
else
if
e
.
which
is
13
or
e
.
which
is
8
# enter key or backspace key has been pressed
if
gl
.
text
.
_previousState
?
gl
.
text
.
undoManager
.
addUndo
(
gl
.
text
.
_previousState
,
$thisTextarea
.
val
()
)
gl
.
text
.
_previousState
=
$thisTextarea
.
val
()
self
.
updateText
(
$this
.
closest
(
'.md-area'
).
find
(
'textarea'
),
$this
.
data
(
'md-tag'
),
not
$this
.
data
(
'md-prepend'
)
)
gl
.
text
.
removeListeners
=
()
->
gl
.
text
.
removeListeners
=
->
$
(
'.js-md'
).
off
()
)
window
\ No newline at end of file
)
window
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录