Browse Source

Fixes for workspace

Nicolas Petton 11 years ago
parent
commit
33a4ae6fd5

+ 5 - 5
js/Helios-Environments.deploy.js

@@ -33,7 +33,7 @@ smalltalk.addMethod(
 "_eval_on_",
 smalltalk.method({
 selector: "eval:on:",
-fn: function (someCode,aReceiver){
+fn: function (aString,aReceiver){
 var self=this;
 var compiler;
 return smalltalk.withContext(function($ctx1) { 
var $1,$2;
@@ -41,17 +41,17 @@ var $early={};
 try {
 compiler=_st((smalltalk.Compiler || Compiler))._new();
 _st((function(){
-return smalltalk.withContext(function($ctx2) {
return _st(compiler)._parseExpression_(someCode);
+return smalltalk.withContext(function($ctx2) {
return _st(compiler)._parseExpression_(aString);
 }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}))._on_do_((smalltalk.Error || Error),(function(ex){
 return smalltalk.withContext(function($ctx2) {
$1=_st(window)._alert_(_st(ex)._messageText());
 throw $early=[$1];
 }, function($ctx2) {$ctx2.fillBlock({ex:ex},$ctx1)})}));
-$2=_st(_st(_st(compiler)._eval_(_st(compiler)._compile_forClass_(_st(_st("doIt ^[").__comma(someCode)).__comma("] value"),(smalltalk.DoIt || DoIt))))._fn())._applyTo_arguments_(aReceiver,[]);
+$2=_st(compiler)._evaluateExpression_on_(aString,aReceiver);
 return $2;
 }
 catch(e) {if(e===$early)return e[0]; throw e}
-}, function($ctx1) {$ctx1.fill(self,"eval:on:",{someCode:someCode,aReceiver:aReceiver,compiler:compiler}, smalltalk.HLLocalEnvironment)})},
-messageSends: ["new", "on:do:", "alert:", "messageText", "parseExpression:", "applyTo:arguments:", "fn", "eval:", "compile:forClass:", ","]}),
+}, function($ctx1) {$ctx1.fill(self,"eval:on:",{aString:aString,aReceiver:aReceiver,compiler:compiler}, smalltalk.HLLocalEnvironment)})},
+messageSends: ["new", "on:do:", "alert:", "messageText", "parseExpression:", "evaluateExpression:on:"]}),
 smalltalk.HLLocalEnvironment);
 
 smalltalk.addMethod(

+ 8 - 8
js/Helios-Environments.js

@@ -45,7 +45,7 @@ smalltalk.addMethod(
 smalltalk.method({
 selector: "eval:on:",
 category: 'actions',
-fn: function (someCode,aReceiver){
+fn: function (aString,aReceiver){
 var self=this;
 var compiler;
 return smalltalk.withContext(function($ctx1) { 
var $1,$2;
@@ -53,20 +53,20 @@ var $early={};
 try {
 compiler=_st((smalltalk.Compiler || Compiler))._new();
 _st((function(){
-return smalltalk.withContext(function($ctx2) {
return _st(compiler)._parseExpression_(someCode);
+return smalltalk.withContext(function($ctx2) {
return _st(compiler)._parseExpression_(aString);
 }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}))._on_do_((smalltalk.Error || Error),(function(ex){
 return smalltalk.withContext(function($ctx2) {
$1=_st(window)._alert_(_st(ex)._messageText());
 throw $early=[$1];
 }, function($ctx2) {$ctx2.fillBlock({ex:ex},$ctx1)})}));
-$2=_st(_st(_st(compiler)._eval_(_st(compiler)._compile_forClass_(_st(_st("doIt ^[").__comma(someCode)).__comma("] value"),(smalltalk.DoIt || DoIt))))._fn())._applyTo_arguments_(aReceiver,[]);
+$2=_st(compiler)._evaluateExpression_on_(aString,aReceiver);
 return $2;
 }
 catch(e) {if(e===$early)return e[0]; throw e}
-}, function($ctx1) {$ctx1.fill(self,"eval:on:",{someCode:someCode,aReceiver:aReceiver,compiler:compiler}, smalltalk.HLLocalEnvironment)})},
-args: ["someCode", "aReceiver"],
-source: "eval: someCode on: aReceiver\x0a\x09| compiler  |\x0a\x09compiler := Compiler new.\x0a\x09[compiler parseExpression: someCode] on: Error do: [:ex |\x0a\x09\x09^window alert: ex messageText].\x0a\x09^(compiler eval: (compiler compile: 'doIt ^[', someCode, '] value' forClass: DoIt)) fn applyTo: aReceiver arguments: #()",
-messageSends: ["new", "on:do:", "alert:", "messageText", "parseExpression:", "applyTo:arguments:", "fn", "eval:", "compile:forClass:", ","],
-referencedClasses: ["Compiler", "Error", "DoIt"]
+}, function($ctx1) {$ctx1.fill(self,"eval:on:",{aString:aString,aReceiver:aReceiver,compiler:compiler}, smalltalk.HLLocalEnvironment)})},
+args: ["aString", "aReceiver"],
+source: "eval: aString on: aReceiver\x0a\x09| compiler  |\x0a\x09compiler := Compiler new.\x0a\x09[ compiler parseExpression: aString ] on: Error do: [ :ex |\x0a\x09\x09^ window alert: ex messageText ].\x0a\x09^ compiler evaluateExpression: aString on: aReceiver",
+messageSends: ["new", "on:do:", "alert:", "messageText", "parseExpression:", "evaluateExpression:on:"],
+referencedClasses: ["Compiler", "Error"]
 }),
 smalltalk.HLLocalEnvironment);
 

+ 12 - 7
js/Helios-Workspace.deploy.js

@@ -393,18 +393,23 @@ smalltalk.method({
 selector: "print:",
 fn: function (aString){
 var self=this;
-var start,stop;
-return smalltalk.withContext(function($ctx1) { 
start=_st((smalltalk.HashedCollection || HashedCollection))._new();
-stop=_st((smalltalk.HashedCollection || HashedCollection))._new();
-_st(start)._at_put_("line",_st(_st(self["@editor"])._getCursor_(false))._line());
+var start,stop,currentLine;
+return smalltalk.withContext(function($ctx1) { 
currentLine=_st(_st(self["@editor"])._getCursor_(false))._line();
+start=_st((smalltalk.HashedCollection || HashedCollection))._new();
+_st(start)._at_put_("line",currentLine);
 _st(start)._at_put_("ch",_st(_st(self["@editor"])._getCursor_(false))._ch());
-_st(stop)._at_put_("line",_st(start)._at_("line"));
+_st(_st(self["@editor"])._getSelection())._ifEmpty_((function(){
+return smalltalk.withContext(function($ctx2) {
_st(start)._at_put_("ch",_st(_st(self["@editor"])._getLine_(currentLine))._size());
+return _st(self["@editor"])._setSelection_end_(smalltalk.HashedCollection._fromPairs_([_st("line").__minus_gt(currentLine),_st("ch").__minus_gt((0))]),start);
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
+stop=_st((smalltalk.HashedCollection || HashedCollection))._new();
+_st(stop)._at_put_("line",currentLine);
 _st(stop)._at_put_("ch",_st(_st(_st(start)._at_("ch")).__plus(_st(aString)._size())).__plus((2)));
 _st(self["@editor"])._replaceSelection_(_st(_st(_st(_st(self["@editor"])._getSelection()).__comma(" ")).__comma(aString)).__comma(" "));
 _st(self["@editor"])._setCursor_(_st(self["@editor"])._getCursor_(true));
 _st(self["@editor"])._setSelection_end_(stop,start);
-return self}, function($ctx1) {$ctx1.fill(self,"print:",{aString:aString,start:start,stop:stop}, smalltalk.HLCodeWidget)})},
-messageSends: ["new", "at:put:", "line", "getCursor:", "ch", "at:", "+", "size", "replaceSelection:", ",", "getSelection", "setCursor:", "setSelection:end:"]}),
+return self}, function($ctx1) {$ctx1.fill(self,"print:",{aString:aString,start:start,stop:stop,currentLine:currentLine}, smalltalk.HLCodeWidget)})},
+messageSends: ["line", "getCursor:", "new", "at:put:", "ch", "ifEmpty:", "size", "getLine:", "setSelection:end:", "->", "getSelection", "+", "at:", "replaceSelection:", ",", "setCursor:"]}),
 smalltalk.HLCodeWidget);
 
 smalltalk.addMethod(

+ 14 - 9
js/Helios-Workspace.js

@@ -282,7 +282,7 @@ $1=_st(self)._currentLine();
 return $1;
 }, function($ctx1) {$ctx1.fill(self,"currentLineOrSelection",{}, smalltalk.HLCodeWidget)})},
 args: [],
-source: "currentLineOrSelection\x0a    ^editor somethingSelected\x0a\x09\x09ifFalse: [self currentLine]\x0a\x09\x09ifTrue: [self selection]",
+source: "currentLineOrSelection\x0a    ^editor somethingSelected\x0a\x09\x09ifFalse: [ self currentLine ]\x0a\x09\x09ifTrue: [ self selection ]",
 messageSends: ["ifFalse:ifTrue:", "currentLine", "selection", "somethingSelected"],
 referencedClasses: []
 }),
@@ -529,20 +529,25 @@ selector: "print:",
 category: 'actions',
 fn: function (aString){
 var self=this;
-var start,stop;
-return smalltalk.withContext(function($ctx1) { 
start=_st((smalltalk.HashedCollection || HashedCollection))._new();
-stop=_st((smalltalk.HashedCollection || HashedCollection))._new();
-_st(start)._at_put_("line",_st(_st(self["@editor"])._getCursor_(false))._line());
+var start,stop,currentLine;
+return smalltalk.withContext(function($ctx1) { 
currentLine=_st(_st(self["@editor"])._getCursor_(false))._line();
+start=_st((smalltalk.HashedCollection || HashedCollection))._new();
+_st(start)._at_put_("line",currentLine);
 _st(start)._at_put_("ch",_st(_st(self["@editor"])._getCursor_(false))._ch());
-_st(stop)._at_put_("line",_st(start)._at_("line"));
+_st(_st(self["@editor"])._getSelection())._ifEmpty_((function(){
+return smalltalk.withContext(function($ctx2) {
_st(start)._at_put_("ch",_st(_st(self["@editor"])._getLine_(currentLine))._size());
+return _st(self["@editor"])._setSelection_end_(smalltalk.HashedCollection._fromPairs_([_st("line").__minus_gt(currentLine),_st("ch").__minus_gt((0))]),start);
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
+stop=_st((smalltalk.HashedCollection || HashedCollection))._new();
+_st(stop)._at_put_("line",currentLine);
 _st(stop)._at_put_("ch",_st(_st(_st(start)._at_("ch")).__plus(_st(aString)._size())).__plus((2)));
 _st(self["@editor"])._replaceSelection_(_st(_st(_st(_st(self["@editor"])._getSelection()).__comma(" ")).__comma(aString)).__comma(" "));
 _st(self["@editor"])._setCursor_(_st(self["@editor"])._getCursor_(true));
 _st(self["@editor"])._setSelection_end_(stop,start);
-return self}, function($ctx1) {$ctx1.fill(self,"print:",{aString:aString,start:start,stop:stop}, smalltalk.HLCodeWidget)})},
+return self}, function($ctx1) {$ctx1.fill(self,"print:",{aString:aString,start:start,stop:stop,currentLine:currentLine}, smalltalk.HLCodeWidget)})},
 args: ["aString"],
-source: "print: aString\x0a\x09| start stop |\x0a\x09start := HashedCollection new.\x0a\x09stop := HashedCollection new.\x0a\x09start at: 'line' put: (editor getCursor: false) line.\x0a\x09start at: 'ch' put: (editor getCursor: false) ch.\x0a\x09stop at: 'line' put: (start at: 'line').\x0a\x09stop at: 'ch' put: ((start at: 'ch') + aString size + 2).\x0a\x09editor replaceSelection: (editor getSelection, ' ', aString, ' ').\x0a\x09editor setCursor: (editor getCursor: true).\x0a\x09editor setSelection: stop end: start",
-messageSends: ["new", "at:put:", "line", "getCursor:", "ch", "at:", "+", "size", "replaceSelection:", ",", "getSelection", "setCursor:", "setSelection:end:"],
+source: "print: aString\x0a\x09| start stop currentLine |\x0a    currentLine := (editor getCursor: false) line.\x0a\x09start := HashedCollection new.\x0a\x09start at: 'line' put: currentLine.\x0a\x09start at: 'ch' put: (editor getCursor: false) ch.\x0a    (editor getSelection) ifEmpty: [\x0a    \x09\x22select current line if selection is empty\x22\x0a    \x09start at: 'ch' put: (editor getLine: currentLine) size.\x0a        editor setSelection: #{'line' -> currentLine. 'ch' -> 0} end: start.\x0a    ].\x0a\x09stop := HashedCollection new.\x0a\x09stop at: 'line' put: currentLine.\x0a\x09stop at: 'ch' put: ((start at: 'ch') + aString size + 2).\x0a\x0a\x09editor replaceSelection: (editor getSelection, ' ', aString, ' ').\x0a\x09editor setCursor: (editor getCursor: true).\x0a\x09editor setSelection: stop end: start",
+messageSends: ["line", "getCursor:", "new", "at:put:", "ch", "ifEmpty:", "size", "getLine:", "setSelection:end:", "->", "getSelection", "+", "at:", "replaceSelection:", ",", "setCursor:"],
 referencedClasses: ["HashedCollection"]
 }),
 smalltalk.HLCodeWidget);

+ 4 - 4
st/Helios-Environments.st

@@ -32,12 +32,12 @@ packages
 
 !HLLocalEnvironment methodsFor: 'actions'!
 
-eval: someCode on: aReceiver
+eval: aString on: aReceiver
 	| compiler  |
 	compiler := Compiler new.
-	[compiler parseExpression: someCode] on: Error do: [:ex |
-		^window alert: ex messageText].
-	^(compiler eval: (compiler compile: 'doIt ^[', someCode, '] value' forClass: DoIt)) fn applyTo: aReceiver arguments: #()
+	[ compiler parseExpression: aString ] on: Error do: [ :ex |
+		^ window alert: ex messageText ].
+	^ compiler evaluateExpression: aString on: aReceiver
 ! !
 
 HLEnvironment subclass: #HLRemoteEnvironment

+ 13 - 6
st/Helios-Workspace.st

@@ -75,8 +75,8 @@ currentLine
 
 currentLineOrSelection
     ^editor somethingSelected
-		ifFalse: [self currentLine]
-		ifTrue: [self selection]
+		ifFalse: [ self currentLine ]
+		ifTrue: [ self selection ]
 !
 
 model
@@ -164,13 +164,20 @@ observeWrapper
 !
 
 print: aString
-	| start stop |
+	| start stop currentLine |
+    currentLine := (editor getCursor: false) line.
 	start := HashedCollection new.
-	stop := HashedCollection new.
-	start at: 'line' put: (editor getCursor: false) line.
+	start at: 'line' put: currentLine.
 	start at: 'ch' put: (editor getCursor: false) ch.
-	stop at: 'line' put: (start at: 'line').
+    (editor getSelection) ifEmpty: [
+    	"select current line if selection is empty"
+    	start at: 'ch' put: (editor getLine: currentLine) size.
+        editor setSelection: #{'line' -> currentLine. 'ch' -> 0} end: start.
+    ].
+	stop := HashedCollection new.
+	stop at: 'line' put: currentLine.
 	stop at: 'ch' put: ((start at: 'ch') + aString size + 2).
+
 	editor replaceSelection: (editor getSelection, ' ', aString, ' ').
 	editor setCursor: (editor getCursor: true).
 	editor setSelection: stop end: start