Browse Source

Cleanups.

Mark Sibly 8 years ago
parent
commit
c58f270893
3 changed files with 69 additions and 66 deletions
  1. 1 0
      .gitignore
  2. 17 12
      modules/mojox/textview.monkey2
  3. 51 54
      src/ted2/monkey2document.monkey2

+ 1 - 0
.gitignore

@@ -47,3 +47,4 @@ Monkey2 (Macos).app
 Monkey2 (Linux)
 
 /src/c2mx2/LLVM
+/src/mx23d

+ 17 - 12
modules/mojox/textview.monkey2

@@ -1092,6 +1092,22 @@ Class TextView Extends ScrollableView
 		Return False
 	End
 	
+	Method OnKeyChar( text:String ) Virtual
+
+		If _undos.Length
+			
+			Local undo:=_undos.Top
+			If Not undo.text And _cursor=undo.cursor
+				ReplaceText( _anchor,_cursor,text )
+				undo.cursor=_cursor
+				Return
+			Endif
+				
+		Endif
+		
+		ReplaceText( text )
+	End
+	
 	Method OnKeyEvent( event:KeyEvent ) Override
 	
 		If _readOnly
@@ -1177,19 +1193,8 @@ Class TextView Extends ScrollableView
 			
 		Case EventType.KeyChar
 		
-			If _undos.Length
-			
-				Local undo:=_undos.Top
-				If Not undo.text And _cursor=undo.cursor
-					ReplaceText( _anchor,_cursor,event.Text )
-					undo.cursor=_cursor
-					Return
-				Endif
-				
-			Endif
+			OnKeyChar( event.Text )
 		
-			ReplaceText( event.Text )
-			
 		End
 	End
 	

+ 51 - 54
src/ted2/monkey2document.monkey2

@@ -346,85 +346,82 @@ Class Monkey2DocumentView Extends Ted2TextView
 		Return text.Slice( start,ends )
 	End
 	
+	Method OnKeyDown:Bool( key:Key,modifiers:Modifier ) Override
 	
-	Method OnKeyEvent( event:KeyEvent ) Override
-	
-		Select event.Type
-		Case EventType.KeyDown
-		
-			Select event.Key
-			Case Key.F1
+		Select key
+		Case Key.F1
 			
-				Local ident:=IdentNearestCursor()
+			Local ident:=IdentNearestCursor()
 				
-				If ident MainWindow.ShowQuickHelp( ident )
+			If ident MainWindow.ShowQuickHelp( ident )
 				
-			Case Key.F2
+		Case Key.F2
 			
-				New Fiber( Lambda()
+			New Fiber( Lambda()
 				
-					Local cmd:="~q"+MainWindow.Mx2ccPath+"~q makeapp -parse -geninfo ~q"+_doc.Path+"~q"
+				Local cmd:="~q"+MainWindow.Mx2ccPath+"~q makeapp -parse -geninfo ~q"+_doc.Path+"~q"
 					
-					Local str:=LoadString( "process::"+cmd )
-					Local i:=str.Find( "{" )
-					If i=-1 Return
-					str=str.Slice( i )
+				Local str:=LoadString( "process::"+cmd )
+				Local i:=str.Find( "{" )
+				If i=-1 Return
+				str=str.Slice( i )
 					
-					Local jobj:=JsonObject.Parse( str )
-					If Not jobj Return
+				Local jobj:=JsonObject.Parse( str )
+				If Not jobj Return
 					
-					Local jsonTree:=New JsonTreeView( jobj )
+				Local jsonTree:=New JsonTreeView( jobj )
 					
-					Local dialog:=New Dialog( "ParseInfo",jsonTree )
-					dialog.AddAction( "Close" ).Triggered=dialog.Close
-					dialog.MinSize=New Vec2i( 512,600 )
+				Local dialog:=New Dialog( "ParseInfo",jsonTree )
+				dialog.AddAction( "Close" ).Triggered=dialog.Close
+				dialog.MinSize=New Vec2i( 512,600 )
 					
-					dialog.Open()
+				dialog.Open()
 				
-				End )
+			End )
 				
-			Case Key.Tab,Key.Enter
+		Case Key.Tab,Key.Enter
 			
-				If _typing Capitalize( False )
+			If _typing Capitalize( False )
 				
-			Case Key.Left
+		Case Key.Left
 			
-				If _typing
-					Local text:=Text
-					Local cursor:=Cursor
-					If cursor And Not IsIdent( text[cursor-1] )
-						Capitalize( True )
-					Endif
+			If _typing
+				Local text:=Text
+				Local cursor:=Cursor
+				If cursor And Not IsIdent( text[cursor-1] )
+					Capitalize( True )
 				Endif
+			Endif
 				
-			Case Key.Right
+		Case Key.Right
 			
-				If _typing
-					Local text:=Text
-					Local cursor:=Cursor
-					If cursor<text.Length And Not IsIdent( text[cursor] )
-						Capitalize( True )
-					Endif
+			If _typing
+				Local text:=Text
+				Local cursor:=Cursor
+				If cursor<text.Length And Not IsIdent( text[cursor] )
+					Capitalize( True )
 				Endif
+			Endif
 				
-			Case Key.Up,Key.Down
+		Case Key.Up,Key.Down
 			
-				Capitalize( True )	'in cased we missed anything...
-			End
-		
-		Case EventType.KeyChar
-		
-			If IsIdent( event.Text[0] )
-				_typing=True
-			Else
-				If _typing Capitalize( False )
-			Endif
+			Capitalize( True )	'in cased we missed anything...
 		End
-
-		Super.OnKeyEvent( event )
-
+		
+		Return Super.OnKeyDown( key,modifiers )
 	End
+	
+	Method OnKeyChar( text:String ) Override
 
+		If IsIdent( text[0] )
+			_typing=True
+		Else
+			If _typing Capitalize( False )
+		Endif
+		
+		Super.OnKeyChar( text )
+	End
+	
 End
 
 Class Monkey2Document Extends Ted2Document