Skip to content

Commit cf63f45

Browse files
authored
better cursor positioning fixes #209
* adjust cursor position on first open #209 * added conditions to cursor col * adjust for : in col condition
1 parent 8cb0fa7 commit cf63f45

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

src/ed.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ D.Ed=function(ide,opts){ //constructor
3636
ed[c]?ed[c](ed.cm):CM.commands[c]?CM.commands[c](ed.cm):0;return!1}
3737
}
3838
ed.setTC(!!ed.tc);this.vt=D.vt(this);this.setLN(D.prf.lineNums())
39+
ed.firstOpen=true;
3940
}
4041
D.Ed.prototype={
4142
updGutters:function(){
@@ -92,7 +93,7 @@ D.Ed.prototype={
9293
this.jumps.forEach(function(x){x.n=x.lh.lineNo()}) //to preserve jumps, convert LineHandle-s to line numbers
9394
cm.setValue(ed.oText=ee.text.join('\n')) //.setValue() invalidates old LineHandle-s
9495
this.jumps.forEach(function(x){x.lh=cm.getLineHandle(x.n);delete x.n}) //look up new LineHandle-s, forget numbers
95-
cm.clearHistory()
96+
cm.clearHistory();
9697
if(D.mac){cm.focus();window.focus()}
9798
//entityType: 16 NestedArray 512 AplClass
9899
// 1 DefinedFunction 32 QuadORObject 1024 AplInterface
@@ -109,7 +110,7 @@ D.Ed.prototype={
109110
ed.dom.getElementsByClassName("tb_RP")[0].style.display="none"
110111
}
111112
var line=ee.currentRow,col=ee.currentColumn||0
112-
if(line===0&&col===0&&ee.text.length===1)col=ee.text[0].length
113+
if(line===0&&col===0&&ee.text.length===1&&/\s?[a-z|@]+$/.test(ee.text[0]))col=ee.text[0].length
113114
cm.setCursor(line,col);cm.scrollIntoView(null,cm.getScrollInfo().clientHeight/2)
114115
ed.oStop=(ee.stop||[]).slice(0).sort(function(x,y){return x-y})
115116
for(var k=0;k<ed.oStop.length;k++)cm.setGutterMarker(ed.oStop[k],'breakpoints',ed.createBPEl())

src/ide.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,12 @@ D.IDE=function(){'use strict'
176176
w.saveScrollPos();
177177
w.cm.setValue(x.text.join('\n'));
178178
if (w.tc)w.hl(u.line);
179+
if (w.firstOpen!==undefined&&w.firstOpen===true){
180+
if (x.text.length===1&&/\s?[a-z|@]+$/.test(x.text[0]))u.ch=w.cm.getLine(u.line).length
181+
else if (x.text[0][0]===":")u.ch=0
182+
else u.ch=1
183+
w.firstOpen=false
184+
}
179185
w.restoreScrollPos();
180186
w.cm.setCursor(u);
181187
},

0 commit comments

Comments
 (0)