forked from kiddkai/atom-node-debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnon-editable-editor.coffee
More file actions
80 lines (62 loc) · 1.73 KB
/
Copy pathnon-editable-editor.coffee
File metadata and controls
80 lines (62 loc) · 1.73 KB
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
{$, View, TextEditorView} = require 'atom-space-pen-views'
Module = require 'module'
path = require 'path'
removeModuleWrapper = (str) ->
lines = str.split('\n');
lines = lines.filter (line) ->
return false if line is Module.wrapper[0]
return true
lines = lines.map (line) ->
if line.indexOf(Module.wrapper[0]) >= 0
return line.replace(Module.wrapper[0], '')
return line
popItem = null
lines.pop()
lines.join('\n')
module.exports =
class NonEditableEditorView extends TextEditorView
@content: TextEditorView.content
initialize: (opts) ->
{
@uri,
@_debugger,
} = opts
if (opts.script)
@id = opts.script.id
@onDone()
return @setText removeModuleWrapper(script.source)
if (opts.id)
@id = opts.id
@_debugger
.getScriptById(@id)
.then (script) =>
@script = script
@setText removeModuleWrapper(script.source)
@onDone()
.then =>
@title = opts.query.name
onDone: ->
extname = path.extname(@script.name)
if extname is '.js'
grammar = atom.grammars.grammarForScopeName('source.js')
else if extname is '.coffee'
grammar = atom.grammars.grammarForScopeName('source.coffee')
else
return
@getModel().setGrammar(grammar)
setCursorBufferPosition: (opts)->
@getModel().setCursorBufferPosition opts, autoscroll: true
markBufferPosition: (opts) ->
@getModel().markBufferPosition(opts)
decorateMarker: (marker, opts) ->
@getModel().decorateMarker(marker, opts)
serialize: ->
uri: @uri
id: @id
script: @script
deserialize: (state) ->
return new NonEditableEditorView(state)
getTitle: ->
@title or 'NativeScript'
getUri: ->
@uri