about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-05-19 22:26:15 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-05-19 22:26:15 -0700
commit8f85b29893b0b1275558e3bf31c2b29f38a3029a (patch)
treeae9a088a4fa45395df404641933e2fcbf2c435b1
parentd4daac442b805eb1a4b3e1fb3edd993359eae31a (diff)
downloadlines.love-8f85b29893b0b1275558e3bf31c2b29f38a3029a.tar.gz
clicking to the right of a wrapped line
-rw-r--r--manual_tests2
-rw-r--r--text.lua18
2 files changed, 11 insertions, 9 deletions
diff --git a/manual_tests b/manual_tests
index 8cfc115..7871ebf 100644
--- a/manual_tests
+++ b/manual_tests
@@ -3,6 +3,8 @@ file load:
   first line is a drawing -> cursor_line = 2
 click on text -> cursor moves
 click on first character of text -> cursor on first character of text
+click to right of text -> cursor past end of line
+click to right of wrapped text -> cursor on final character of line
 click on drawing -> cursor doesn't move
 create drawing -> cursor bumps down below drawing
 backspace
diff --git a/text.lua b/text.lua
index 216ba32..647a71d 100644
--- a/text.lua
+++ b/text.lua
@@ -47,6 +47,7 @@ function Text.draw(line, line_width, line_index, cursor_line, cursor_pos)
   if line.fragments == nil then
     Text.compute_fragments(line, line_width)
   end
+  line.screen_line_starting_pos = nil
   for _, f in ipairs(line.fragments) do
     local frag, frag_text = f.data, f.text
     -- render fragment
@@ -279,24 +280,23 @@ end
 function Text.move_cursor(line_index, line, mx, my)
   Cursor_line = line_index
   if line.screen_line_starting_pos == nil then
---?     print('single screen line')
     Cursor_pos = Text.nearest_cursor_pos(line.data, mx)
     return
   end
   assert(line.fragments)
   assert(my >= line.y)
---?   print('move_cursor', mx, my)
-  if my < line.y + math.floor(15*Zoom) then
---?     print('first screen line')
-    Cursor_pos = Text.nearest_cursor_pos(line.data, mx)
-    return
-  end
   -- duplicate some logic from Text.draw
   local y = line.y
-  for _,screen_line_starting_pos in ipairs(line.screen_line_starting_pos) do
---?     print('screen line:', screen_line_starting_pos)
+  for screen_line_index,screen_line_starting_pos in ipairs(line.screen_line_starting_pos) do
     local nexty = y + math.floor(15*Zoom)
     if my < nexty then
+      -- On all wrapped screen lines but the final one, clicks past end of
+      -- line position cursor on final character of screen line.
+      -- (The final screen line positions past end of screen line as always.)
+      if mx > Line_width and screen_line_index < #line.screen_line_starting_pos then
+        Cursor_pos = line.screen_line_starting_pos[screen_line_index+1] - 1
+        return
+      end
       local s = string.sub(line.data, screen_line_starting_pos)
       Cursor_pos = screen_line_starting_pos + Text.nearest_cursor_pos(s, mx) - 1
       return
> 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453