FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
atom/src/text-editor-view.coffee at master · msoftware/atom · GitHub
msoftware
/
atom
Public
forked from
atom/atom
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
atom
/
src
/
text-editor-view.coffee
Copy path
More file actions
More file actions
Latest commit
History
History
History
328 lines (267 loc) · 11 KB
Breadcrumbs
atom
/
src
/
text-editor-view.coffee
Copy path
File metadata and controls
328 lines (267 loc) · 11 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
{
View
,
$
}
=
require
'
space-pen
'
React
=
require
'
react-atom-fork
'
{
defaults
}
=
require
'
underscore-plus
'
TextBuffer
=
require
'
text-buffer
'
TextEditor
=
require
'
./text-editor
'
TextEditorElement
=
require
'
./text-editor-element
'
TextEditorComponent
=
require
'
./text-editor-component
'
{
deprecate
}
=
require
'
grim
'
#
Deprecated: Represents the entire visual pane in Atom.
#
#
The TextEditorView manages the {TextEditor}, which manages the file buffers.
#
`TextEditorView` is intentionally sparse. Most of the things you'll want
#
to do are on {TextEditor}.
#
#
## Examples
#
#
Requiring in packages
#
#
```coffee
#
{TextEditorView} = require 'atom'
#
#
miniEditorView = new TextEditorView(mini: true)
#
```
#
#
Iterating over the open editor views
#
#
```coffee
#
for editorView in atom.workspaceView.getEditorViews()
#
console.log(editorView.getModel().getPath())
#
```
#
#
Subscribing to every current and future editor
#
#
```coffee
#
atom.workspace.eachEditorView (editorView) ->
#
console.log(editorView.getModel().getPath())
#
```
module
.
exports
=
class
TextEditorView
extends
View
#
The constructor for setting up an `TextEditorView` instance.
#
#
* `modelOrParams` Either an {TextEditor}, or an object with one property, `mini`.
#
If `mini` is `true`, a "miniature" `TextEditor` is constructed.
#
Typically, this is ideal for scenarios where you need an Atom editor,
#
but without all the chrome, like scrollbars, gutter, _e.t.c._.
#
constructor
:
(
modelOrParams
,
props
)
->
#
Handle direct construction with an editor or params
unless
modelOrParams
instanceof
HTMLElement
if
modelOrParams
instanceof
TextEditor
model
=
modelOrParams
else
{
editor
,
mini
,
placeholderText
,
attributes
}
=
modelOrParams
model
=
editor
?
new
TextEditor
buffer
:
new
TextBuffer
softWrapped
:
false
tabLength
:
2
softTabs
:
true
mini
:
mini
placeholderText
:
placeholderText
element
=
new
TextEditorElement
element
.
lineOverdrawMargin
=
props
?
.
lineOverdrawMargin
element
.
setAttribute
(name, value)
for
name, value
of
attributes
if
attributes
?
element
.
setModel
(model)
return
element
.
__spacePenView
#
Handle construction with an element
@element
=
modelOrParams
super
setModel
:
(
@model
)
->
@editor
=
@model
@root
=
$
(
@element
.
rootElement
)
@scrollView
=
@root
.
find
(
'
.scroll-view
'
)
if
atom
.
config
.
get
(
'
editor.useShadowDOM
'
)
@underlayer
=
$
(
"
<div class='underlayer'></div>
"
).
appendTo
(
this
)
@overlayer
=
$
(
"
<div class='overlayer'></div>
"
).
appendTo
(
this
)
else
@underlayer
=
@
find
(
'
.highlights
'
).
addClass
(
'
underlayer
'
)
@overlayer
=
@
find
(
'
.lines
'
).
addClass
(
'
overlayer
'
)
@hiddenInput
=
@root
.
find
(
'
.hidden-input
'
)
@hiddenInput
.
on
=
(
args
...
)
=>
args[
0
]
=
'
blur
'
if
args[
0
]
is
'
focusout
'
$
::
on
.
apply
(
this
, args)
@
subscribe
atom
.
config
.
observe
'
editor.showLineNumbers
'
,
=>
@gutter
=
@root
.
find
(
'
.gutter
'
)
@gutter
.
removeClassFromAllLines
=
(
klass
)
=>
deprecate
(
'
Use decorations instead: http://blog.atom.io/2014/07/24/decorations.html
'
)
@gutter
.
find
(
'
.line-number
'
).
removeClass
(klass)
@gutter
.
getLineNumberElement
=
(
bufferRow
)
=>
deprecate
(
'
Use decorations instead: http://blog.atom.io/2014/07/24/decorations.html
'
)
@gutter
.
find
(
"
[data-buffer-row='
#{
bufferRow
}
']
"
)
@gutter
.
addClassToLine
=
(
bufferRow
,
klass
)
=>
deprecate
(
'
Use decorations instead: http://blog.atom.io/2014/07/24/decorations.html
'
)
lines
=
@gutter
.
find
(
"
[data-buffer-row='
#{
bufferRow
}
']
"
)
lines
.
addClass
(klass)
lines
.
length
>
0
find
:
->
shadowResult
=
@root
.
find
.
apply
(
@root
,
arguments
)
if
shadowResult
.
length
>
0
shadowResult
else
super
#
Public: Get the underlying editor model for this view.
#
#
Returns an {TextEditor}
getModel
:
->
@model
getEditor
:
->
@model
Object
.
defineProperty
@
::
,
'
lineHeight
'
,
get
:
->
@model
.
getLineHeightInPixels
()
Object
.
defineProperty
@
::
,
'
charWidth
'
,
get
:
->
@model
.
getDefaultCharWidth
()
Object
.
defineProperty
@
::
,
'
firstRenderedScreenRow
'
,
get
:
->
@component
.
getRenderedRowRange
()[
0
]
Object
.
defineProperty
@
::
,
'
lastRenderedScreenRow
'
,
get
:
->
@component
.
getRenderedRowRange
()[
1
]
Object
.
defineProperty
@
::
,
'
active
'
,
get
:
->
@
is
(
@
getPaneView
()
?
.
activeView
)
Object
.
defineProperty
@
::
,
'
isFocused
'
,
get
:
->
document
.
activeElement
is
@element
or
document
.
activeElement
is
@element
.
component
?
.
refs
.
input
.
getDOMNode
()
Object
.
defineProperty
@
::
,
'
mini
'
,
get
:
->
@model
?
.
isMini
()
Object
.
defineProperty
@
::
,
'
component
'
,
get
:
->
@element
?
.
component
afterAttach
:
(
onDom
)
->
return
unless
onDom
return
if
@attached
@attached
=
true
@
trigger
'
editor:attached
'
, [
this
]
beforeRemove
:
->
@
trigger
'
editor:detached
'
, [
this
]
@
trigger
'
editor:will-be-removed
'
, [
this
]
@attached
=
false
remove
:
(
selector
,
keepData
)
->
@model
.
destroy
()
unless
keepData
super
scrollTop
:
(
scrollTop
)
->
if
scrollTop
?
@model
.
setScrollTop
(scrollTop)
else
@model
.
getScrollTop
()
scrollLeft
:
(
scrollLeft
)
->
if
scrollLeft
?
@model
.
setScrollLeft
(scrollLeft)
else
@model
.
getScrollLeft
()
scrollToBottom
:
->
deprecate
'
Use TextEditor::scrollToBottom instead. You can get the editor via editorView.getModel()
'
@model
.
setScrollBottom
(
Infinity
)
scrollToScreenPosition
:
(
screenPosition
,
options
)
->
deprecate
'
Use TextEditor::scrollToScreenPosition instead. You can get the editor via editorView.getModel()
'
@model
.
scrollToScreenPosition
(screenPosition, options)
scrollToBufferPosition
:
(
bufferPosition
,
options
)
->
deprecate
'
Use TextEditor::scrollToBufferPosition instead. You can get the editor via editorView.getModel()
'
@model
.
scrollToBufferPosition
(bufferPosition, options)
scrollToCursorPosition
:
->
deprecate
'
Use TextEditor::scrollToCursorPosition instead. You can get the editor via editorView.getModel()
'
@model
.
scrollToCursorPosition
()
pixelPositionForBufferPosition
:
(
bufferPosition
)
->
deprecate
'
Use TextEditorElement::pixelPositionForBufferPosition instead. You can get the editor via editorView.getModel()
'
@model
.
pixelPositionForBufferPosition
(bufferPosition,
true
)
pixelPositionForScreenPosition
:
(
screenPosition
)
->
deprecate
'
Use TextEditorElement::pixelPositionForScreenPosition instead. You can get the editor via editorView.getModel()
'
@model
.
pixelPositionForScreenPosition
(screenPosition,
true
)
appendToLinesView
:
(
view
)
->
view
.
css
(
'
position
'
,
'
absolute
'
)
view
.
css
(
'
z-index
'
,
1
)
@overlayer
.
append
(view)
unmountComponent
:
->
React
.
unmountComponentAtNode
(
@element
)
if
@component
.
isMounted
()
splitLeft
:
->
deprecate
"""
Use Pane::splitLeft instead.
To duplicate this editor into the split use:
editorView.getPaneView().getModel().splitLeft(copyActiveItem: true)
"""
pane
=
@
getPaneView
()
pane
?
.
splitLeft
(
pane
?
.
copyActiveItem
()).
activeView
splitRight
:
->
deprecate
"""
Use Pane::splitRight instead.
To duplicate this editor into the split use:
editorView.getPaneView().getModel().splitRight(copyActiveItem: true)
"""
pane
=
@
getPaneView
()
pane
?
.
splitRight
(
pane
?
.
copyActiveItem
()).
activeView
splitUp
:
->
deprecate
"""
Use Pane::splitUp instead.
To duplicate this editor into the split use:
editorView.getPaneView().getModel().splitUp(copyActiveItem: true)
"""
pane
=
@
getPaneView
()
pane
?
.
splitUp
(
pane
?
.
copyActiveItem
()).
activeView
splitDown
:
->
deprecate
"""
Use Pane::splitDown instead.
To duplicate this editor into the split use:
editorView.getPaneView().getModel().splitDown(copyActiveItem: true)
"""
pane
=
@
getPaneView
()
pane
?
.
splitDown
(
pane
?
.
copyActiveItem
()).
activeView
#
Public: Get this {TextEditorView}'s {PaneView}.
#
#
Returns a {PaneView}
getPaneView
:
->
@
parent
(
'
.item-views
'
).
parents
(
'
atom-pane
'
).
view
()
getPane
:
->
deprecate
'
Use TextEditorView::getPaneView() instead
'
@
getPaneView
()
show
:
->
super
@component
?
.
checkForVisibilityChange
()
hide
:
->
super
@component
?
.
checkForVisibilityChange
()
pageDown
:
->
deprecate
(
'
Use editorView.getModel().pageDown()
'
)
@model
.
pageDown
()
pageUp
:
->
deprecate
(
'
Use editorView.getModel().pageUp()
'
)
@model
.
pageUp
()
getFirstVisibleScreenRow
:
->
deprecate
'
Use TextEditorElement::getFirstVisibleScreenRow instead.
'
@model
.
getFirstVisibleScreenRow
(
true
)
getLastVisibleScreenRow
:
->
deprecate
'
Use TextEditor::getLastVisibleScreenRow instead. You can get the editor via editorView.getModel()
'
@model
.
getLastVisibleScreenRow
()
getFontFamily
:
->
deprecate
'
This is going away. Use atom.config.get("editor.fontFamily") instead
'
@component
?
.
getFontFamily
()
setFontFamily
:
(
fontFamily
)
->
deprecate
'
This is going away. Use atom.config.set("editor.fontFamily", "my-font") instead
'
@component
?
.
setFontFamily
(fontFamily)
getFontSize
:
->
deprecate
'
This is going away. Use atom.config.get("editor.fontSize") instead
'
@component
?
.
getFontSize
()
setFontSize
:
(
fontSize
)
->
deprecate
'
This is going away. Use atom.config.set("editor.fontSize", 12) instead
'
@component
?
.
setFontSize
(fontSize)
setLineHeight
:
(
lineHeight
)
->
deprecate
'
This is going away. Use atom.config.set("editor.lineHeight", 1.5) instead
'
@component
.
setLineHeight
(lineHeight)
setWidthInChars
:
(
widthInChars
)
->
@component
.
getDOMNode
().
style
.
width
=
(
@model
.
getDefaultCharWidth
()
*
widthInChars)
+
'
px
'
setShowIndentGuide
:
(
showIndentGuide
)
->
deprecate
'
This is going away. Use atom.config.set("editor.showIndentGuide", true|false) instead
'
atom
.
config
.
set
(
"
editor.showIndentGuide
"
, showIndentGuide)
setSoftWrap
:
(
softWrapped
)
->
deprecate
'
Use TextEditor::setSoftWrapped instead. You can get the editor via editorView.getModel()
'
@model
.
setSoftWrapped
(softWrapped)
setShowInvisibles
:
(
showInvisibles
)
->
deprecate
'
This is going away. Use atom.config.set("editor.showInvisibles", true|false) instead
'
@component
.
setShowInvisibles
(showInvisibles)
getText
:
->
@model
.
getText
()
setText
:
(
text
)
->
@model
.
setText
(text)
insertText
:
(
text
)
->
@model
.
insertText
(text)
isInputEnabled
:
->
@component
.
isInputEnabled
()
setInputEnabled
:
(
inputEnabled
)
->
@component
.
setInputEnabled
(inputEnabled)
requestDisplayUpdate
:
->
deprecate
(
'
Please remove from your code. ::requestDisplayUpdate no longer does anything
'
)
updateDisplay
:
->
deprecate
(
'
Please remove from your code. ::updateDisplay no longer does anything
'
)
resetDisplay
:
->
deprecate
(
'
Please remove from your code. ::resetDisplay no longer does anything
'
)
redraw
:
->
deprecate
(
'
Please remove from your code. ::redraw no longer does anything
'
)
setPlaceholderText
:
(
placeholderText
)
->
deprecate
(
'
Use TextEditor::setPlaceholderText instead. eg. editorView.getModel().setPlaceholderText(text)
'
)
@model
.
setPlaceholderText
(placeholderText)
lineElementForScreenRow
:
(
screenRow
)
->
$
(
@component
.
lineNodeForScreenRow
(screenRow))
Back
|
FazBrowse Home
|
New Git URL