Jelajahi Sumber

fix edittext and richedittext :eyes:

SakiKawasaki 4 tahun lalu
induk
melakukan
ac2266733c

+ 4 - 5
src/nodesnim/nodescontrol/edittext.nim

@@ -258,11 +258,10 @@ method handle*(self: EditTextRef, event: InputEvent, mouse_on: var NodeRef) =
 
   if self.focused:
     if event.kind == KEYBOARD:
-      if event.key_cint in pressed_keys_cints:  # Special chars
-        if event.key_cint == K_LEFT and self.caret_position > 0:
-          self.caret_position -= 1
-        elif event.key_cint == K_RIGHT and self.caret_position < self.text.len():
-          self.caret_position += 1
+      if event.key_cint == K_LEFT and self.caret_position > 0:
+        self.caret_position -= 1
+      elif event.key_cint == K_RIGHT and self.caret_position < self.text.len():
+        self.caret_position += 1
       elif event.key in pressed_keys:  # Normal chars
         if event.key_int == 8:  # Backspace
           if self.caret_position > 1 and self.caret_position < self.text.len():

+ 4 - 5
src/nodesnim/nodescontrol/rich_edit_text.nim

@@ -250,11 +250,10 @@ method handle*(self: RichEditTextRef, event: InputEvent, mouse_on: var NodeRef)
 
   if self.focused:
     if event.kind == KEYBOARD:
-      if event.key_cint in pressed_keys_cints:  # Special chars
-        if event.key_cint == K_LEFT and self.caret_position > 0:
-          self.caret_position -= 1
-        elif event.key_cint == K_RIGHT and self.caret_position < self.text.len():
-          self.caret_position += 1
+      if event.key_cint == K_LEFT and self.caret_position > 0:
+        self.caret_position -= 1
+      elif event.key_cint == K_RIGHT and self.caret_position < self.text.len():
+        self.caret_position += 1
       elif event.key in pressed_keys:  # Normal chars
         if event.key_int == 8:  # Backspace
           if self.caret_position > 1 and self.caret_position < self.text.len():

+ 3 - 0
src/nodesnim/window.nim

@@ -158,6 +158,7 @@ proc keyboardspecialpress(c: cint, x, y: cint) {.cdecl.} =
   if c < 0:
     return
   check(InputEventKeyboard, last_event.pressed, true)
+  last_event.key = $c
   last_event.key_cint = c
   last_event.x = x.float
   last_event.y = y.float
@@ -292,6 +293,8 @@ proc windowLaunch* =
   glutSpecialUpFunc(keyboardspecialup)
   glutMotionFunc(motion)
   glutPassiveMotionFunc(motion)
+  glutIgnoreKeyRepeat(K_SHIFT)
+  glutIgnoreKeyRepeat(K_RIGHT_SHIFT)
   if main_scene == nil:
     raise newException(MainSceneNotLoadedError, "Main scene is not indicated!")
   changeScene(main_scene.name)

+ 2 - 2
tests/test19.nim

@@ -21,10 +21,10 @@ label.on_process =
     label.text.setUnderline(false)
 
     # Nim highlight
-    var start_position = ($label.text).find("nim")
+    var start_position = ($label.text).find("Nim")
     while start_position > -1:
       label.text.setColor(start_position, start_position+2, Color(0xaa99ffff'u32))
-      start_position = ($label.text).find("nim", start_position+2)
+      start_position = ($label.text).find("Nim", start_position+2)
 
     # word underline
     if label.text.len() > 0: