Always show indent guides
This commit is contained in:
parent
15aeb7631f
commit
a5a955ca6b
1 changed files with 61 additions and 62 deletions
|
@ -275,78 +275,77 @@ module.exports = class SpellView extends CocoView
|
||||||
e.editor.execCommand 'gotolineend'
|
e.editor.execCommand 'gotolineend'
|
||||||
return true
|
return true
|
||||||
|
|
||||||
if me.level() < 20 or aceConfig.indentGuides
|
# Add visual indent guides
|
||||||
# Add visual ident guides
|
language = @spell.language
|
||||||
language = @spell.language
|
ensureLineStartsBlock = (line) ->
|
||||||
ensureLineStartsBlock = (line) ->
|
return false unless language is "python"
|
||||||
return false unless language is "python"
|
match = /^\s*([^#]+)/.exec(line)
|
||||||
match = /^\s*([^#]+)/.exec(line)
|
return false if not match?
|
||||||
return false if not match?
|
return /:\s*$/.test(match[1])
|
||||||
return /:\s*$/.test(match[1])
|
|
||||||
|
|
||||||
@aceSession.addDynamicMarker
|
@aceSession.addDynamicMarker
|
||||||
update: (html, markerLayer, session, config) =>
|
update: (html, markerLayer, session, config) =>
|
||||||
Range = ace.require('ace/range').Range
|
Range = ace.require('ace/range').Range
|
||||||
|
|
||||||
foldWidgets = @aceSession.foldWidgets
|
foldWidgets = @aceSession.foldWidgets
|
||||||
return if not foldWidgets?
|
return if not foldWidgets?
|
||||||
|
|
||||||
lines = @aceDoc.getAllLines()
|
lines = @aceDoc.getAllLines()
|
||||||
startOfRow = (r) ->
|
startOfRow = (r) ->
|
||||||
str = lines[r]
|
str = lines[r]
|
||||||
ar = str.match(/^\s*/)
|
ar = str.match(/^\s*/)
|
||||||
ar.pop().length
|
ar.pop().length
|
||||||
|
|
||||||
colors = [{border: '74,144,226', fill: '108,162,226'}, {border: '132,180,235', fill: '230,237,245'}]
|
colors = [{border: '74,144,226', fill: '108,162,226'}, {border: '132,180,235', fill: '230,237,245'}]
|
||||||
|
|
||||||
for row in [0..@aceSession.getLength()]
|
for row in [0..@aceSession.getLength()]
|
||||||
foldWidgets[row] = @aceSession.getFoldWidget(row) unless foldWidgets[row]?
|
foldWidgets[row] = @aceSession.getFoldWidget(row) unless foldWidgets[row]?
|
||||||
continue unless foldWidgets? and foldWidgets[row] is "start"
|
continue unless foldWidgets? and foldWidgets[row] is "start"
|
||||||
try
|
try
|
||||||
docRange = @aceSession.getFoldWidgetRange(row)
|
docRange = @aceSession.getFoldWidgetRange(row)
|
||||||
catch error
|
catch error
|
||||||
console.warn "Couldn't find fold widget docRange for row #{row}:", error
|
console.warn "Couldn't find fold widget docRange for row #{row}:", error
|
||||||
if not docRange?
|
if not docRange?
|
||||||
guess = startOfRow(row)
|
guess = startOfRow(row)
|
||||||
docRange = new Range(row,guess,row,guess+4)
|
docRange = new Range(row,guess,row,guess+4)
|
||||||
|
|
||||||
continue unless ensureLineStartsBlock(lines[row])
|
continue unless ensureLineStartsBlock(lines[row])
|
||||||
|
|
||||||
if /^\s+$/.test lines[docRange.end.row+1]
|
if /^\s+$/.test lines[docRange.end.row+1]
|
||||||
docRange.end.row += 1
|
docRange.end.row += 1
|
||||||
|
|
||||||
xstart = startOfRow(row)
|
xstart = startOfRow(row)
|
||||||
if language is 'python'
|
if language is 'python'
|
||||||
requiredIndent = new RegExp '^' + new Array(Math.floor(xstart / 4 + 1)).join('( |\t)') + '( |\t)+(\\S|\\s*$)'
|
requiredIndent = new RegExp '^' + new Array(Math.floor(xstart / 4 + 1)).join('( |\t)') + '( |\t)+(\\S|\\s*$)'
|
||||||
for crow in [docRange.start.row+1..docRange.end.row]
|
for crow in [docRange.start.row+1..docRange.end.row]
|
||||||
unless requiredIndent.test lines[crow]
|
unless requiredIndent.test lines[crow]
|
||||||
docRange.end.row = crow - 1
|
docRange.end.row = crow - 1
|
||||||
break
|
break
|
||||||
|
|
||||||
rstart = @aceSession.documentToScreenPosition docRange.start.row, docRange.start.column
|
rstart = @aceSession.documentToScreenPosition docRange.start.row, docRange.start.column
|
||||||
rend = @aceSession.documentToScreenPosition docRange.end.row, docRange.end.column
|
rend = @aceSession.documentToScreenPosition docRange.end.row, docRange.end.column
|
||||||
range = new Range rstart.row, rstart.column, rend.row, rend.column
|
range = new Range rstart.row, rstart.column, rend.row, rend.column
|
||||||
level = Math.floor(xstart / 4)
|
level = Math.floor(xstart / 4)
|
||||||
color = colors[level % colors.length]
|
color = colors[level % colors.length]
|
||||||
bw = 3
|
bw = 3
|
||||||
to = markerLayer.$getTop(range.start.row, config)
|
to = markerLayer.$getTop(range.start.row, config)
|
||||||
t = markerLayer.$getTop(range.start.row + 1, config)
|
t = markerLayer.$getTop(range.start.row + 1, config)
|
||||||
h = config.lineHeight * (range.end.row - range.start.row)
|
h = config.lineHeight * (range.end.row - range.start.row)
|
||||||
l = markerLayer.$padding + xstart * config.characterWidth
|
l = markerLayer.$padding + xstart * config.characterWidth
|
||||||
# w = (data.i - data.b) * config.characterWidth
|
# w = (data.i - data.b) * config.characterWidth
|
||||||
w = 4 * config.characterWidth
|
w = 4 * config.characterWidth
|
||||||
fw = config.characterWidth * ( @aceSession.getScreenLastRowColumn(range.start.row) - xstart )
|
fw = config.characterWidth * ( @aceSession.getScreenLastRowColumn(range.start.row) - xstart )
|
||||||
|
|
||||||
html.push """
|
html.push """
|
||||||
<div style=
|
<div style=
|
||||||
"position: absolute; top: #{to}px; left: #{l}px; width: #{fw+bw}px; height: #{config.lineHeight}px;
|
"position: absolute; top: #{to}px; left: #{l}px; width: #{fw+bw}px; height: #{config.lineHeight}px;
|
||||||
border: #{bw}px solid rgba(#{color.border},1); border-left: none;"
|
border: #{bw}px solid rgba(#{color.border},1); border-left: none;"
|
||||||
></div>
|
></div>
|
||||||
<div style=
|
<div style=
|
||||||
"position: absolute; top: #{t}px; left: #{l}px; width: #{w}px; height: #{h}px; background-color: rgba(#{color.fill},0.5);
|
"position: absolute; top: #{t}px; left: #{l}px; width: #{w}px; height: #{h}px; background-color: rgba(#{color.fill},0.5);
|
||||||
border-right: #{bw}px solid rgba(#{color.border},1); border-bottom: #{bw}px solid rgba(#{color.border},1);"
|
border-right: #{bw}px solid rgba(#{color.border},1); border-bottom: #{bw}px solid rgba(#{color.border},1);"
|
||||||
></div>
|
></div>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
fillACE: ->
|
fillACE: ->
|
||||||
@ace.setValue @spell.source
|
@ace.setValue @spell.source
|
||||||
|
|
Reference in a new issue