Changeset View
Changeset View
Standalone View
Standalone View
src/view/kateviewinternal.cpp
Show First 20 Lines • Show All 306 Lines • ▼ Show 20 Line(s) | |||||
307 | { | 307 | { | ||
308 | // Which is the current view line? | 308 | // Which is the current view line? | ||
309 | m_wrapChangeViewLine = cache()->displayViewLine(m_displayCursor, true); | 309 | m_wrapChangeViewLine = cache()->displayViewLine(m_displayCursor, true); | ||
310 | } | 310 | } | ||
311 | 311 | | |||
312 | void KateViewInternal::dynWrapChanged() | 312 | void KateViewInternal::dynWrapChanged() | ||
313 | { | 313 | { | ||
314 | m_dummy->setFixedSize(m_lineScroll->width(), m_columnScroll->sizeHint().height()); | 314 | m_dummy->setFixedSize(m_lineScroll->width(), m_columnScroll->sizeHint().height()); | ||
315 | if (m_view->dynWordWrap()) { | 315 | if (view()->dynWordWrap()) { | ||
316 | m_columnScroll->hide(); | 316 | m_columnScroll->hide(); | ||
317 | m_dummy->hide(); | 317 | m_dummy->hide(); | ||
318 | 318 | | |||
319 | } else { | 319 | } else { | ||
320 | // column scrollbar + bottom corner box | 320 | // column scrollbar + bottom corner box | ||
321 | m_columnScroll->show(); | 321 | m_columnScroll->show(); | ||
322 | m_dummy->show(); | 322 | m_dummy->show(); | ||
323 | } | 323 | } | ||
324 | 324 | | |||
325 | cache()->setWrap(m_view->dynWordWrap()); | 325 | cache()->setWrap(view()->dynWordWrap()); | ||
326 | updateView(); | 326 | updateView(); | ||
327 | 327 | | |||
328 | if (m_view->dynWordWrap()) { | 328 | if (view()->dynWordWrap()) { | ||
329 | scrollColumns(0); | 329 | scrollColumns(0); | ||
330 | } | 330 | } | ||
331 | 331 | | |||
332 | // Determine where the cursor should be to get the cursor on the same view line | 332 | // Determine where the cursor should be to get the cursor on the same view line | ||
333 | if (m_wrapChangeViewLine != -1) { | 333 | if (m_wrapChangeViewLine != -1) { | ||
334 | KTextEditor::Cursor newStart = viewLineOffset(m_displayCursor, -m_wrapChangeViewLine); | 334 | KTextEditor::Cursor newStart = viewLineOffset(m_displayCursor, -m_wrapChangeViewLine); | ||
335 | makeVisible(newStart, newStart.column(), true); | 335 | makeVisible(newStart, newStart.column(), true); | ||
336 | 336 | | |||
Show All 11 Lines | 343 | { | |||
348 | 348 | | |||
349 | for (int i = qMin(linesDisplayed() - 1, cache()->viewCacheLineCount() - 1); i >= 0; i--) { | 349 | for (int i = qMin(linesDisplayed() - 1, cache()->viewCacheLineCount() - 1); i >= 0; i--) { | ||
350 | const KateTextLayout &thisLine = cache()->viewLine(i); | 350 | const KateTextLayout &thisLine = cache()->viewLine(i); | ||
351 | 351 | | |||
352 | if (thisLine.line() == -1) { | 352 | if (thisLine.line() == -1) { | ||
353 | continue; | 353 | continue; | ||
354 | } | 354 | } | ||
355 | 355 | | |||
356 | if (thisLine.virtualLine() >= m_view->textFolding().visibleLines()) { | 356 | if (thisLine.virtualLine() >= view()->textFolding().visibleLines()) { | ||
357 | // Cache is too out of date | 357 | // Cache is too out of date | ||
358 | return KTextEditor::Cursor(m_view->textFolding().visibleLines() - 1, doc()->lineLength(m_view->textFolding().visibleLineToLine(m_view->textFolding().visibleLines() - 1))); | 358 | return KTextEditor::Cursor(view()->textFolding().visibleLines() - 1, doc()->lineLength(view()->textFolding().visibleLineToLine(view()->textFolding().visibleLines() - 1))); | ||
359 | } | 359 | } | ||
360 | 360 | | |||
361 | return KTextEditor::Cursor(thisLine.virtualLine(), thisLine.wrap() ? thisLine.endCol() - 1 : thisLine.endCol()); | 361 | return KTextEditor::Cursor(thisLine.virtualLine(), thisLine.wrap() ? thisLine.endCol() - 1 : thisLine.endCol()); | ||
362 | } | 362 | } | ||
363 | 363 | | |||
364 | // can happen, if view is still invisible | 364 | // can happen, if view is still invisible | ||
365 | return KTextEditor::Cursor(); | 365 | return KTextEditor::Cursor(); | ||
366 | } | 366 | } | ||
▲ Show 20 Lines • Show All 103 Lines • ▼ Show 20 Line(s) | 469 | { | |||
470 | scrollViewLines(1); | 470 | scrollViewLines(1); | ||
471 | } | 471 | } | ||
472 | 472 | | |||
473 | KTextEditor::Cursor KateViewInternal::maxStartPos(bool changed) | 473 | KTextEditor::Cursor KateViewInternal::maxStartPos(bool changed) | ||
474 | { | 474 | { | ||
475 | cache()->setAcceptDirtyLayouts(true); | 475 | cache()->setAcceptDirtyLayouts(true); | ||
476 | 476 | | |||
477 | if (m_cachedMaxStartPos.line() == -1 || changed) { | 477 | if (m_cachedMaxStartPos.line() == -1 || changed) { | ||
478 | KTextEditor::Cursor end(m_view->textFolding().visibleLines() - 1, doc()->lineLength(m_view->textFolding().visibleLineToLine(m_view->textFolding().visibleLines() - 1))); | 478 | KTextEditor::Cursor end(view()->textFolding().visibleLines() - 1, doc()->lineLength(view()->textFolding().visibleLineToLine(view()->textFolding().visibleLines() - 1))); | ||
479 | 479 | | |||
480 | if (m_view->config()->scrollPastEnd()) { | 480 | if (view()->config()->scrollPastEnd()) { | ||
481 | m_cachedMaxStartPos = viewLineOffset(end, -m_minLinesVisible); | 481 | m_cachedMaxStartPos = viewLineOffset(end, -m_minLinesVisible); | ||
482 | } else { | 482 | } else { | ||
483 | m_cachedMaxStartPos = viewLineOffset(end, -(linesDisplayed() - 1)); | 483 | m_cachedMaxStartPos = viewLineOffset(end, -(linesDisplayed() - 1)); | ||
484 | } | 484 | } | ||
485 | } | 485 | } | ||
486 | 486 | | |||
487 | cache()->setAcceptDirtyLayouts(false); | 487 | cache()->setAcceptDirtyLayouts(false); | ||
488 | 488 | | |||
489 | return m_cachedMaxStartPos; | 489 | return m_cachedMaxStartPos; | ||
490 | } | 490 | } | ||
491 | 491 | | |||
492 | // c is a virtual cursor | 492 | // c is a virtual cursor | ||
493 | void KateViewInternal::scrollPos(KTextEditor::Cursor &c, bool force, bool calledExternally, bool emitSignals) | 493 | void KateViewInternal::scrollPos(KTextEditor::Cursor &c, bool force, bool calledExternally, bool emitSignals) | ||
494 | { | 494 | { | ||
495 | if (!force && ((!m_view->dynWordWrap() && c.line() == startLine()) || c == startPos())) { | 495 | if (!force && ((!view()->dynWordWrap() && c.line() == startLine()) || c == startPos())) { | ||
496 | return; | 496 | return; | ||
497 | } | 497 | } | ||
498 | 498 | | |||
499 | if (c.line() < 0) { | 499 | if (c.line() < 0) { | ||
500 | c.setLine(0); | 500 | c.setLine(0); | ||
501 | } | 501 | } | ||
502 | 502 | | |||
503 | KTextEditor::Cursor limit = maxStartPos(); | 503 | KTextEditor::Cursor limit = maxStartPos(); | ||
504 | if (c > limit) { | 504 | if (c > limit) { | ||
505 | c = limit; | 505 | c = limit; | ||
506 | 506 | | |||
507 | // Re-check we're not just scrolling to the same place | 507 | // Re-check we're not just scrolling to the same place | ||
508 | if (!force && ((!m_view->dynWordWrap() && c.line() == startLine()) || c == startPos())) { | 508 | if (!force && ((!view()->dynWordWrap() && c.line() == startLine()) || c == startPos())) { | ||
509 | return; | 509 | return; | ||
510 | } | 510 | } | ||
511 | } | 511 | } | ||
512 | 512 | | |||
513 | int viewLinesScrolled = 0; | 513 | int viewLinesScrolled = 0; | ||
514 | 514 | | |||
515 | // only calculate if this is really used and useful, could be wrong here, please recheck | 515 | // only calculate if this is really used and useful, could be wrong here, please recheck | ||
516 | // for larger scrolls this makes 2-4 seconds difference on my xeon with dyn. word wrap on | 516 | // for larger scrolls this makes 2-4 seconds difference on my xeon with dyn. word wrap on | ||
517 | // try to get it really working ;) | 517 | // try to get it really working ;) | ||
518 | bool viewLinesScrolledUsable = !force | 518 | bool viewLinesScrolledUsable = !force | ||
519 | && (c.line() >= startLine() - linesDisplayed() - 1) | 519 | && (c.line() >= startLine() - linesDisplayed() - 1) | ||
520 | && (c.line() <= endLine() + linesDisplayed() + 1); | 520 | && (c.line() <= endLine() + linesDisplayed() + 1); | ||
521 | 521 | | |||
522 | if (viewLinesScrolledUsable) { | 522 | if (viewLinesScrolledUsable) { | ||
523 | viewLinesScrolled = cache()->displayViewLine(c); | 523 | viewLinesScrolled = cache()->displayViewLine(c); | ||
524 | } | 524 | } | ||
525 | 525 | | |||
526 | m_startPos.setPosition(c); | 526 | m_startPos.setPosition(c); | ||
527 | 527 | | |||
528 | // set false here but reversed if we return to makeVisible | 528 | // set false here but reversed if we return to makeVisible | ||
529 | m_madeVisible = false; | 529 | m_madeVisible = false; | ||
530 | 530 | | |||
531 | if (viewLinesScrolledUsable) { | 531 | if (viewLinesScrolledUsable) { | ||
532 | int lines = linesDisplayed(); | 532 | int lines = linesDisplayed(); | ||
533 | if (m_view->textFolding().visibleLines() < lines) { | 533 | if (view()->textFolding().visibleLines() < lines) { | ||
534 | KTextEditor::Cursor end(m_view->textFolding().visibleLines() - 1, doc()->lineLength(m_view->textFolding().visibleLineToLine(m_view->textFolding().visibleLines() - 1))); | 534 | KTextEditor::Cursor end(view()->textFolding().visibleLines() - 1, doc()->lineLength(view()->textFolding().visibleLineToLine(view()->textFolding().visibleLines() - 1))); | ||
535 | lines = qMin(linesDisplayed(), cache()->displayViewLine(end) + 1); | 535 | lines = qMin(linesDisplayed(), cache()->displayViewLine(end) + 1); | ||
536 | } | 536 | } | ||
537 | 537 | | |||
538 | Q_ASSERT(lines >= 0); | 538 | Q_ASSERT(lines >= 0); | ||
539 | 539 | | |||
540 | if (!calledExternally && qAbs(viewLinesScrolled) < lines && | 540 | if (!calledExternally && qAbs(viewLinesScrolled) < lines && | ||
541 | // NOTE: on some machines we must update if the floating widget is visible | 541 | // NOTE: on some machines we must update if the floating widget is visible | ||
542 | // otherwise strange painting bugs may occur during scrolling... | 542 | // otherwise strange painting bugs may occur during scrolling... | ||
543 | !((m_view->m_messageWidgets[KTextEditor::Message::TopInView] && | 543 | !((view()->m_messageWidgets[KTextEditor::Message::TopInView] && | ||
544 | m_view->m_messageWidgets[KTextEditor::Message::TopInView]->isVisible()) | 544 | view()->m_messageWidgets[KTextEditor::Message::TopInView]->isVisible()) | ||
545 | ||(m_view->m_messageWidgets[KTextEditor::Message::CenterInView] && | 545 | ||(view()->m_messageWidgets[KTextEditor::Message::CenterInView] && | ||
546 | m_view->m_messageWidgets[KTextEditor::Message::CenterInView]->isVisible()) | 546 | view()->m_messageWidgets[KTextEditor::Message::CenterInView]->isVisible()) | ||
547 | ||(m_view->m_messageWidgets[KTextEditor::Message::BottomInView] && | 547 | ||(view()->m_messageWidgets[KTextEditor::Message::BottomInView] && | ||
548 | m_view->m_messageWidgets[KTextEditor::Message::BottomInView]->isVisible()) | 548 | view()->m_messageWidgets[KTextEditor::Message::BottomInView]->isVisible()) | ||
549 | ) | 549 | ) | ||
550 | ) { | 550 | ) { | ||
551 | updateView(false, viewLinesScrolled); | 551 | updateView(false, viewLinesScrolled); | ||
552 | 552 | | |||
553 | int scrollHeight = -(viewLinesScrolled * (int)renderer()->lineHeight()); | 553 | int scrollHeight = -(viewLinesScrolled * (int)renderer()->lineHeight()); | ||
554 | 554 | | |||
555 | // scroll excluding child widgets (floating notifications) | 555 | // scroll excluding child widgets (floating notifications) | ||
556 | scroll(0, scrollHeight, rect()); | 556 | scroll(0, scrollHeight, rect()); | ||
557 | m_leftBorder->scroll(0, scrollHeight); | 557 | m_leftBorder->scroll(0, scrollHeight); | ||
558 | 558 | | |||
559 | if (emitSignals) { | 559 | if (emitSignals) { | ||
560 | emit m_view->verticalScrollPositionChanged(m_view, c); | 560 | emit view()->verticalScrollPositionChanged(m_view, c); | ||
561 | emit m_view->displayRangeChanged(m_view); | 561 | emit view()->displayRangeChanged(m_view); | ||
562 | } | 562 | } | ||
563 | return; | 563 | return; | ||
564 | } | 564 | } | ||
565 | } | 565 | } | ||
566 | 566 | | |||
567 | updateView(); | 567 | updateView(); | ||
568 | update(); | 568 | update(); | ||
569 | m_leftBorder->update(); | 569 | m_leftBorder->update(); | ||
570 | if (emitSignals) { | 570 | if (emitSignals) { | ||
571 | emit m_view->verticalScrollPositionChanged(m_view, c); | 571 | emit view()->verticalScrollPositionChanged(m_view, c); | ||
572 | emit m_view->displayRangeChanged(m_view); | 572 | emit view()->displayRangeChanged(m_view); | ||
573 | } | 573 | } | ||
574 | } | 574 | } | ||
575 | 575 | | |||
576 | void KateViewInternal::scrollColumns(int x) | 576 | void KateViewInternal::scrollColumns(int x) | ||
577 | { | 577 | { | ||
578 | if (x < 0) { | 578 | if (x < 0) { | ||
579 | x = 0; | 579 | x = 0; | ||
580 | } | 580 | } | ||
581 | 581 | | |||
582 | if (x > m_columnScroll->maximum()) { | 582 | if (x > m_columnScroll->maximum()) { | ||
583 | x = m_columnScroll->maximum(); | 583 | x = m_columnScroll->maximum(); | ||
584 | } | 584 | } | ||
585 | 585 | | |||
586 | if (x == m_startX) { | 586 | if (x == startX()) { | ||
587 | return; | 587 | return; | ||
588 | } | 588 | } | ||
589 | 589 | | |||
590 | int dx = m_startX - x; | 590 | int dx = startX() - x; | ||
591 | m_startX = x; | 591 | m_startX = x; | ||
592 | 592 | | |||
593 | if (qAbs(dx) < width()) { | 593 | if (qAbs(dx) < width()) { | ||
594 | // scroll excluding child widgets (floating notifications) | 594 | // scroll excluding child widgets (floating notifications) | ||
595 | scroll(dx, 0, rect()); | 595 | scroll(dx, 0, rect()); | ||
596 | } else { | 596 | } else { | ||
597 | update(); | 597 | update(); | ||
598 | } | 598 | } | ||
599 | 599 | | |||
600 | emit m_view->horizontalScrollPositionChanged(m_view); | 600 | emit view()->horizontalScrollPositionChanged(m_view); | ||
601 | emit m_view->displayRangeChanged(m_view); | 601 | emit view()->displayRangeChanged(m_view); | ||
602 | 602 | | |||
603 | bool blocked = m_columnScroll->blockSignals(true); | 603 | bool blocked = m_columnScroll->blockSignals(true); | ||
604 | m_columnScroll->setValue(m_startX); | 604 | m_columnScroll->setValue(startX()); | ||
605 | m_columnScroll->blockSignals(blocked); | 605 | m_columnScroll->blockSignals(blocked); | ||
606 | } | 606 | } | ||
607 | 607 | | |||
608 | // If changed is true, the lines that have been set dirty have been updated. | 608 | // If changed is true, the lines that have been set dirty have been updated. | ||
609 | void KateViewInternal::updateView(bool changed, int viewLinesScrolled) | 609 | void KateViewInternal::updateView(bool changed, int viewLinesScrolled) | ||
610 | { | 610 | { | ||
611 | if (!isVisible() && !viewLinesScrolled && !changed) { | 611 | if (!isVisible() && !viewLinesScrolled && !changed) { | ||
612 | return; //When this view is not visible, don't do anything | 612 | return; //When this view is not visible, don't do anything | ||
Show All 12 Lines | 622 | /* It was observed that height() could be negative here -- | |||
625 | case we'd set the view cache to 0 (or less!) lines, and | 625 | case we'd set the view cache to 0 (or less!) lines, and | ||
626 | start allocating huge chunks of data, later. */ | 626 | start allocating huge chunks of data, later. */ | ||
627 | int newSize = (qMax(0, height()) / renderer()->lineHeight()) + 1; | 627 | int newSize = (qMax(0, height()) / renderer()->lineHeight()) + 1; | ||
628 | cache()->updateViewCache(startPos(), newSize, viewLinesScrolled); | 628 | cache()->updateViewCache(startPos(), newSize, viewLinesScrolled); | ||
629 | m_visibleLineCount = newSize; | 629 | m_visibleLineCount = newSize; | ||
630 | 630 | | |||
631 | KTextEditor::Cursor maxStart = maxStartPos(changed); | 631 | KTextEditor::Cursor maxStart = maxStartPos(changed); | ||
632 | int maxLineScrollRange = maxStart.line(); | 632 | int maxLineScrollRange = maxStart.line(); | ||
633 | if (m_view->dynWordWrap() && maxStart.column() != 0) { | 633 | if (view()->dynWordWrap() && maxStart.column() != 0) { | ||
634 | maxLineScrollRange++; | 634 | maxLineScrollRange++; | ||
635 | } | 635 | } | ||
636 | m_lineScroll->setRange(0, maxLineScrollRange); | 636 | m_lineScroll->setRange(0, maxLineScrollRange); | ||
637 | 637 | | |||
638 | m_lineScroll->setValue(startPos().line()); | 638 | m_lineScroll->setValue(startLine()); | ||
639 | m_lineScroll->setSingleStep(1); | 639 | m_lineScroll->setSingleStep(1); | ||
640 | m_lineScroll->setPageStep(qMax(0, height()) / renderer()->lineHeight()); | 640 | m_lineScroll->setPageStep(qMax(0, height()) / renderer()->lineHeight()); | ||
641 | m_lineScroll->blockSignals(blocked); | 641 | m_lineScroll->blockSignals(blocked); | ||
642 | 642 | | |||
643 | KateViewConfig::ScrollbarMode show_scrollbars = static_cast<KateViewConfig::ScrollbarMode>(view()->config()->showScrollbars()); | 643 | KateViewConfig::ScrollbarMode show_scrollbars = static_cast<KateViewConfig::ScrollbarMode>(view()->config()->showScrollbars()); | ||
644 | 644 | | |||
645 | bool visible = ((show_scrollbars == KateViewConfig::AlwaysOn) || | 645 | bool visible = ((show_scrollbars == KateViewConfig::AlwaysOn) || | ||
646 | ((show_scrollbars == KateViewConfig::ShowWhenNeeded) && (maxLineScrollRange != 0))); | 646 | ((show_scrollbars == KateViewConfig::ShowWhenNeeded) && (maxLineScrollRange != 0))); | ||
647 | bool visible_dummy = visible; | 647 | bool visible_dummy = visible; | ||
648 | 648 | | |||
649 | m_lineScroll->setVisible(visible); | 649 | m_lineScroll->setVisible(visible); | ||
650 | 650 | | |||
651 | if (!m_view->dynWordWrap()) { | 651 | if (!view()->dynWordWrap()) { | ||
652 | int max = maxLen(startLine()) - width(); | 652 | int max = maxLen(startLine()) - width(); | ||
653 | if (max < 0) { | 653 | if (max < 0) { | ||
654 | max = 0; | 654 | max = 0; | ||
655 | } | 655 | } | ||
656 | 656 | | |||
657 | // if we lose the ability to scroll horizontally, move view to the far-left | 657 | // if we lose the ability to scroll horizontally, move view to the far-left | ||
658 | if (max == 0) { | 658 | if (max == 0) { | ||
659 | scrollColumns(0); | 659 | scrollColumns(0); | ||
660 | } | 660 | } | ||
661 | 661 | | |||
662 | blocked = m_columnScroll->blockSignals(true); | 662 | blocked = m_columnScroll->blockSignals(true); | ||
663 | 663 | | |||
664 | // disable scrollbar | 664 | // disable scrollbar | ||
665 | m_columnScroll->setDisabled(max == 0); | 665 | m_columnScroll->setDisabled(max == 0); | ||
666 | 666 | | |||
667 | visible = ((show_scrollbars == KateViewConfig::AlwaysOn) || | 667 | visible = ((show_scrollbars == KateViewConfig::AlwaysOn) || | ||
668 | ((show_scrollbars == KateViewConfig::ShowWhenNeeded) && (max != 0))); | 668 | ((show_scrollbars == KateViewConfig::ShowWhenNeeded) && (max != 0))); | ||
669 | visible_dummy &= visible; | 669 | visible_dummy &= visible; | ||
670 | m_columnScroll->setVisible(visible); | 670 | m_columnScroll->setVisible(visible); | ||
671 | 671 | | |||
672 | m_columnScroll->setRange(0, max + (renderer()->spaceWidth() / 2)); // Add some space for the caret at EOL | 672 | m_columnScroll->setRange(0, max + (renderer()->spaceWidth() / 2)); // Add some space for the caret at EOL | ||
673 | 673 | | |||
674 | m_columnScroll->setValue(m_startX); | 674 | m_columnScroll->setValue(startX()); | ||
675 | 675 | | |||
676 | // Approximate linescroll | 676 | // Approximate linescroll | ||
677 | m_columnScroll->setSingleStep(renderer()->config()->fontMetrics().width(QLatin1Char('a'))); | 677 | m_columnScroll->setSingleStep(renderer()->config()->fontMetrics().width(QLatin1Char('a'))); | ||
678 | m_columnScroll->setPageStep(width()); | 678 | m_columnScroll->setPageStep(width()); | ||
679 | 679 | | |||
680 | m_columnScroll->blockSignals(blocked); | 680 | m_columnScroll->blockSignals(blocked); | ||
681 | } else { | 681 | } else { | ||
682 | visible_dummy = false; | 682 | visible_dummy = false; | ||
Show All 32 Lines | 697 | { | |||
715 | } else { | 715 | } else { | ||
716 | // Check to see that we're not showing blank lines | 716 | // Check to see that we're not showing blank lines | ||
717 | KTextEditor::Cursor max = maxStartPos(); | 717 | KTextEditor::Cursor max = maxStartPos(); | ||
718 | if (startPos() > max) { | 718 | if (startPos() > max) { | ||
719 | scrollPos(max, max.column(), calledExternally); | 719 | scrollPos(max, max.column(), calledExternally); | ||
720 | } | 720 | } | ||
721 | } | 721 | } | ||
722 | 722 | | |||
723 | if (!m_view->dynWordWrap() && (endCol != -1 || m_view->wrapCursor())) { | 723 | if (!view()->dynWordWrap() && (endCol != -1 || view()->wrapCursor())) { | ||
724 | KTextEditor::Cursor rc = toRealCursor(c); | 724 | KTextEditor::Cursor rc = toRealCursor(c); | ||
725 | int sX = renderer()->cursorToX(cache()->textLayout(rc), rc, !m_view->wrapCursor()); | 725 | int sX = renderer()->cursorToX(cache()->textLayout(rc), rc, !view()->wrapCursor()); | ||
726 | 726 | | |||
727 | int sXborder = sX - 8; | 727 | int sXborder = sX - 8; | ||
728 | if (sXborder < 0) { | 728 | if (sXborder < 0) { | ||
729 | sXborder = 0; | 729 | sXborder = 0; | ||
730 | } | 730 | } | ||
731 | 731 | | |||
732 | if (sX < m_startX) { | 732 | if (sX < startX()) { | ||
733 | scrollColumns(sXborder); | 733 | scrollColumns(sXborder); | ||
734 | } else if (sX > m_startX + width()) { | 734 | } else if (sX > startX() + width()) { | ||
735 | scrollColumns(sX - width() + 8); | 735 | scrollColumns(sX - width() + 8); | ||
736 | } | 736 | } | ||
737 | } | 737 | } | ||
738 | 738 | | |||
739 | m_madeVisible = !force; | 739 | m_madeVisible = !force; | ||
740 | 740 | | |||
741 | #ifndef QT_NO_ACCESSIBILITY | 741 | #ifndef QT_NO_ACCESSIBILITY | ||
742 | // FIXME -- is this needed? | 742 | // FIXME -- is this needed? | ||
Show All 10 Lines | 749 | { | |||
753 | m_cachedMaxStartPos.setLine(-1); | 753 | m_cachedMaxStartPos.setLine(-1); | ||
754 | KTextEditor::Cursor max = maxStartPos(); | 754 | KTextEditor::Cursor max = maxStartPos(); | ||
755 | if (startPos() > max) { | 755 | if (startPos() > max) { | ||
756 | scrollPos(max, false, false, false /* don't emit signals! */); | 756 | scrollPos(max, false, false, false /* don't emit signals! */); | ||
757 | } | 757 | } | ||
758 | 758 | | |||
759 | // if text was folded: make sure the cursor is on a visible line | 759 | // if text was folded: make sure the cursor is on a visible line | ||
760 | qint64 foldedRangeId = -1; | 760 | qint64 foldedRangeId = -1; | ||
761 | if (!m_view->textFolding().isLineVisible(m_cursor.line(), &foldedRangeId)) { | 761 | if (!view()->textFolding().isLineVisible(m_cursor.line(), &foldedRangeId)) { | ||
762 | KTextEditor::Range foldingRange = m_view->textFolding().foldingRange(foldedRangeId); | 762 | KTextEditor::Range foldingRange = view()->textFolding().foldingRange(foldedRangeId); | ||
763 | Q_ASSERT(foldingRange.start().isValid()); | 763 | Q_ASSERT(foldingRange.start().isValid()); | ||
764 | 764 | | |||
765 | // set cursor to start of folding region | 765 | // set cursor to start of folding region | ||
766 | updateCursor(foldingRange.start(), true); | 766 | updateCursor(foldingRange.start(), true); | ||
767 | } else { | 767 | } else { | ||
768 | // force an update of the cursor, since otherwise the m_displayCursor | 768 | // force an update of the cursor, since otherwise the m_displayCursor | ||
769 | // line may be below the total amount of visible lines. | 769 | // line may be below the total amount of visible lines. | ||
770 | updateCursor(m_cursor, true); | 770 | updateCursor(m_cursor, true); | ||
771 | } | 771 | } | ||
772 | 772 | | |||
773 | updateView(); | 773 | updateView(); | ||
774 | update(); | 774 | update(); | ||
775 | m_leftBorder->update(); | 775 | m_leftBorder->update(); | ||
776 | 776 | | |||
777 | // emit signals here, scrollPos has this disabled, to ensure we do this after all stuff is updated! | 777 | // emit signals here, scrollPos has this disabled, to ensure we do this after all stuff is updated! | ||
778 | emit m_view->verticalScrollPositionChanged(m_view, max); | 778 | emit view()->verticalScrollPositionChanged(m_view, max); | ||
779 | emit m_view->displayRangeChanged(m_view); | 779 | emit view()->displayRangeChanged(m_view); | ||
780 | } | 780 | } | ||
781 | 781 | | |||
782 | void KateViewInternal::slotRegionBeginEndAddedRemoved(unsigned int) | 782 | void KateViewInternal::slotRegionBeginEndAddedRemoved(unsigned int) | ||
783 | { | 783 | { | ||
784 | qCDebug(LOG_KTE); | 784 | qCDebug(LOG_KTE); | ||
785 | // FIXME: performance problem | 785 | // FIXME: performance problem | ||
786 | m_leftBorder->update(); | 786 | m_leftBorder->update(); | ||
787 | } | 787 | } | ||
▲ Show 20 Lines • Show All 358 Lines • ▼ Show 20 Line(s) | 1067 | public: | |||
1146 | { | 1146 | { | ||
1147 | return operator+=(-n); | 1147 | return operator+=(-n); | ||
1148 | } | 1148 | } | ||
1149 | }; | 1149 | }; | ||
1150 | 1150 | | |||
1151 | void KateViewInternal::moveChar(KateViewInternal::Bias bias, bool sel) | 1151 | void KateViewInternal::moveChar(KateViewInternal::Bias bias, bool sel) | ||
1152 | { | 1152 | { | ||
1153 | KTextEditor::Cursor c; | 1153 | KTextEditor::Cursor c; | ||
1154 | if (m_view->wrapCursor()) { | 1154 | if (view()->wrapCursor()) { | ||
1155 | c = WrappingCursor(this, m_cursor) += bias; | 1155 | c = WrappingCursor(this, m_cursor) += bias; | ||
1156 | } else { | 1156 | } else { | ||
1157 | c = BoundedCursor(this, m_cursor) += bias; | 1157 | c = BoundedCursor(this, m_cursor) += bias; | ||
1158 | } | 1158 | } | ||
1159 | 1159 | | |||
1160 | updateSelection(c, sel); | 1160 | updateSelection(c, sel); | ||
1161 | updateCursor(c); | 1161 | updateCursor(c); | ||
1162 | } | 1162 | } | ||
1163 | 1163 | | |||
1164 | void KateViewInternal::cursorPrevChar(bool sel) | 1164 | void KateViewInternal::cursorPrevChar(bool sel) | ||
1165 | { | 1165 | { | ||
1166 | if (! m_view->wrapCursor() && m_cursor.column() == 0) { | 1166 | if (! view()->wrapCursor() && m_cursor.column() == 0) { | ||
1167 | return; | 1167 | return; | ||
1168 | } | 1168 | } | ||
1169 | 1169 | | |||
1170 | moveChar(KateViewInternal::left, sel); | 1170 | moveChar(KateViewInternal::left, sel); | ||
1171 | } | 1171 | } | ||
1172 | 1172 | | |||
1173 | void KateViewInternal::cursorNextChar(bool sel) | 1173 | void KateViewInternal::cursorNextChar(bool sel) | ||
1174 | { | 1174 | { | ||
▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Line(s) | 1255 | { | |||
1256 | BoundedCursor c(this, m_cursor); | 1256 | BoundedCursor c(this, m_cursor); | ||
1257 | c.toEdge(bias); | 1257 | c.toEdge(bias); | ||
1258 | updateSelection(c, sel); | 1258 | updateSelection(c, sel); | ||
1259 | updateCursor(c); | 1259 | updateCursor(c); | ||
1260 | } | 1260 | } | ||
1261 | 1261 | | |||
1262 | void KateViewInternal::home(bool sel) | 1262 | void KateViewInternal::home(bool sel) | ||
1263 | { | 1263 | { | ||
1264 | if (m_view->dynWordWrap() && currentLayout().startCol()) { | 1264 | if (view()->dynWordWrap() && currentLayout().startCol()) { | ||
1265 | // Allow us to go to the real start if we're already at the start of the view line | 1265 | // Allow us to go to the real start if we're already at the start of the view line | ||
1266 | if (m_cursor.column() != currentLayout().startCol()) { | 1266 | if (m_cursor.column() != currentLayout().startCol()) { | ||
1267 | KTextEditor::Cursor c = currentLayout().start(); | 1267 | KTextEditor::Cursor c = currentLayout().start(); | ||
1268 | updateSelection(c, sel); | 1268 | updateSelection(c, sel); | ||
1269 | updateCursor(c); | 1269 | updateCursor(c); | ||
1270 | return; | 1270 | return; | ||
1271 | } | 1271 | } | ||
1272 | } | 1272 | } | ||
Show All 21 Lines | |||||
1294 | updateSelection(c, sel); | 1294 | updateSelection(c, sel); | ||
1295 | updateCursor(c, true); | 1295 | updateCursor(c, true); | ||
1296 | } | 1296 | } | ||
1297 | 1297 | | |||
1298 | void KateViewInternal::end(bool sel) | 1298 | void KateViewInternal::end(bool sel) | ||
1299 | { | 1299 | { | ||
1300 | KateTextLayout layout = currentLayout(); | 1300 | KateTextLayout layout = currentLayout(); | ||
1301 | 1301 | | |||
1302 | if (m_view->dynWordWrap() && layout.wrap()) { | 1302 | if (view()->dynWordWrap() && layout.wrap()) { | ||
1303 | // Allow us to go to the real end if we're already at the end of the view line | 1303 | // Allow us to go to the real end if we're already at the end of the view line | ||
1304 | if (m_cursor.column() < layout.endCol() - 1) { | 1304 | if (m_cursor.column() < layout.endCol() - 1) { | ||
1305 | KTextEditor::Cursor c(m_cursor.line(), layout.endCol() - 1); | 1305 | KTextEditor::Cursor c(m_cursor.line(), layout.endCol() - 1); | ||
1306 | updateSelection(c, sel); | 1306 | updateSelection(c, sel); | ||
1307 | updateCursor(c); | 1307 | updateCursor(c); | ||
1308 | return; | 1308 | return; | ||
1309 | } | 1309 | } | ||
1310 | } | 1310 | } | ||
Show All 27 Lines | |||||
1338 | 1338 | | |||
1339 | KateTextLayout KateViewInternal::previousLayout() const | 1339 | KateTextLayout KateViewInternal::previousLayout() const | ||
1340 | { | 1340 | { | ||
1341 | int currentViewLine = cache()->viewLine(m_cursor); | 1341 | int currentViewLine = cache()->viewLine(m_cursor); | ||
1342 | 1342 | | |||
1343 | if (currentViewLine) { | 1343 | if (currentViewLine) { | ||
1344 | return cache()->textLayout(m_cursor.line(), currentViewLine - 1); | 1344 | return cache()->textLayout(m_cursor.line(), currentViewLine - 1); | ||
1345 | } else { | 1345 | } else { | ||
1346 | return cache()->textLayout(m_view->textFolding().visibleLineToLine(m_displayCursor.line() - 1), -1); | 1346 | return cache()->textLayout(view()->textFolding().visibleLineToLine(m_displayCursor.line() - 1), -1); | ||
1347 | } | 1347 | } | ||
1348 | } | 1348 | } | ||
1349 | 1349 | | |||
1350 | KateTextLayout KateViewInternal::nextLayout() const | 1350 | KateTextLayout KateViewInternal::nextLayout() const | ||
1351 | { | 1351 | { | ||
1352 | int currentViewLine = cache()->viewLine(m_cursor) + 1; | 1352 | int currentViewLine = cache()->viewLine(m_cursor) + 1; | ||
1353 | 1353 | | |||
1354 | if (currentViewLine >= cache()->line(m_cursor.line())->viewLineCount()) { | 1354 | if (currentViewLine >= cache()->line(m_cursor.line())->viewLineCount()) { | ||
1355 | currentViewLine = 0; | 1355 | currentViewLine = 0; | ||
1356 | return cache()->textLayout(m_view->textFolding().visibleLineToLine(m_displayCursor.line() + 1), currentViewLine); | 1356 | return cache()->textLayout(view()->textFolding().visibleLineToLine(m_displayCursor.line() + 1), currentViewLine); | ||
1357 | } else { | 1357 | } else { | ||
1358 | return cache()->textLayout(m_cursor.line(), currentViewLine); | 1358 | return cache()->textLayout(m_cursor.line(), currentViewLine); | ||
1359 | } | 1359 | } | ||
1360 | } | 1360 | } | ||
1361 | 1361 | | |||
1362 | /* | 1362 | /* | ||
1363 | * This returns the cursor which is offset by (offset) view lines. | 1363 | * This returns the cursor which is offset by (offset) view lines. | ||
1364 | * This is the main function which is called by code not specifically dealing with word-wrap. | 1364 | * This is the main function which is called by code not specifically dealing with word-wrap. | ||
1365 | * The opposite conversion (cursor to offset) can be done with cache()->displayViewLine(). | 1365 | * The opposite conversion (cursor to offset) can be done with cache()->displayViewLine(). | ||
1366 | * | 1366 | * | ||
1367 | * The cursors involved are virtual cursors (ie. equivalent to m_displayCursor) | 1367 | * The cursors involved are virtual cursors (ie. equivalent to m_displayCursor) | ||
1368 | */ | 1368 | */ | ||
1369 | 1369 | | |||
1370 | KTextEditor::Cursor KateViewInternal::viewLineOffset(const KTextEditor::Cursor &virtualCursor, int offset, bool keepX) | 1370 | KTextEditor::Cursor KateViewInternal::viewLineOffset(const KTextEditor::Cursor &virtualCursor, int offset, bool keepX) | ||
1371 | { | 1371 | { | ||
1372 | if (!m_view->dynWordWrap()) { | 1372 | if (!view()->dynWordWrap()) { | ||
1373 | KTextEditor::Cursor ret(qMin((int)m_view->textFolding().visibleLines() - 1, virtualCursor.line() + offset), 0); | 1373 | KTextEditor::Cursor ret(qMin((int)view()->textFolding().visibleLines() - 1, virtualCursor.line() + offset), 0); | ||
1374 | 1374 | | |||
1375 | if (ret.line() < 0) { | 1375 | if (ret.line() < 0) { | ||
1376 | ret.setLine(0); | 1376 | ret.setLine(0); | ||
1377 | } | 1377 | } | ||
1378 | 1378 | | |||
1379 | if (keepX) { | 1379 | if (keepX) { | ||
1380 | int realLine = m_view->textFolding().visibleLineToLine(ret.line()); | 1380 | int realLine = view()->textFolding().visibleLineToLine(ret.line()); | ||
1381 | KateTextLayout t = cache()->textLayout(realLine, 0); | 1381 | KateTextLayout t = cache()->textLayout(realLine, 0); | ||
1382 | Q_ASSERT(t.isValid()); | 1382 | Q_ASSERT(t.isValid()); | ||
1383 | 1383 | | |||
1384 | ret.setColumn(renderer()->xToCursor(t, m_preservedX, !m_view->wrapCursor()).column()); | 1384 | ret.setColumn(renderer()->xToCursor(t, m_preservedX, !view()->wrapCursor()).column()); | ||
1385 | } | 1385 | } | ||
1386 | 1386 | | |||
1387 | return ret; | 1387 | return ret; | ||
1388 | } | 1388 | } | ||
1389 | 1389 | | |||
1390 | KTextEditor::Cursor realCursor = virtualCursor; | 1390 | KTextEditor::Cursor realCursor = virtualCursor; | ||
1391 | realCursor.setLine(m_view->textFolding().visibleLineToLine(m_view->textFolding().lineToVisibleLine(virtualCursor.line()))); | 1391 | realCursor.setLine(view()->textFolding().visibleLineToLine(view()->textFolding().lineToVisibleLine(virtualCursor.line()))); | ||
1392 | 1392 | | |||
1393 | int cursorViewLine = cache()->viewLine(realCursor); | 1393 | int cursorViewLine = cache()->viewLine(realCursor); | ||
1394 | 1394 | | |||
1395 | int currentOffset = 0; | 1395 | int currentOffset = 0; | ||
1396 | int virtualLine = 0; | 1396 | int virtualLine = 0; | ||
1397 | 1397 | | |||
1398 | bool forwards = (offset > 0) ? true : false; | 1398 | bool forwards = (offset > 0) ? true : false; | ||
1399 | 1399 | | |||
1400 | if (forwards) { | 1400 | if (forwards) { | ||
1401 | currentOffset = cache()->lastViewLine(realCursor.line()) - cursorViewLine; | 1401 | currentOffset = cache()->lastViewLine(realCursor.line()) - cursorViewLine; | ||
1402 | if (offset <= currentOffset) { | 1402 | if (offset <= currentOffset) { | ||
1403 | // the answer is on the same line | 1403 | // the answer is on the same line | ||
1404 | KateTextLayout thisLine = cache()->textLayout(realCursor.line(), cursorViewLine + offset); | 1404 | KateTextLayout thisLine = cache()->textLayout(realCursor.line(), cursorViewLine + offset); | ||
1405 | Q_ASSERT(thisLine.virtualLine() == (int) m_view->textFolding().lineToVisibleLine(virtualCursor.line())); | 1405 | Q_ASSERT(thisLine.virtualLine() == (int) view()->textFolding().lineToVisibleLine(virtualCursor.line())); | ||
1406 | return KTextEditor::Cursor(virtualCursor.line(), thisLine.startCol()); | 1406 | return KTextEditor::Cursor(virtualCursor.line(), thisLine.startCol()); | ||
1407 | } | 1407 | } | ||
1408 | 1408 | | |||
1409 | virtualLine = virtualCursor.line() + 1; | 1409 | virtualLine = virtualCursor.line() + 1; | ||
1410 | 1410 | | |||
1411 | } else { | 1411 | } else { | ||
1412 | offset = -offset; | 1412 | offset = -offset; | ||
1413 | currentOffset = cursorViewLine; | 1413 | currentOffset = cursorViewLine; | ||
1414 | if (offset <= currentOffset) { | 1414 | if (offset <= currentOffset) { | ||
1415 | // the answer is on the same line | 1415 | // the answer is on the same line | ||
1416 | KateTextLayout thisLine = cache()->textLayout(realCursor.line(), cursorViewLine - offset); | 1416 | KateTextLayout thisLine = cache()->textLayout(realCursor.line(), cursorViewLine - offset); | ||
1417 | Q_ASSERT(thisLine.virtualLine() == (int) m_view->textFolding().lineToVisibleLine(virtualCursor.line())); | 1417 | Q_ASSERT(thisLine.virtualLine() == (int) view()->textFolding().lineToVisibleLine(virtualCursor.line())); | ||
1418 | return KTextEditor::Cursor(virtualCursor.line(), thisLine.startCol()); | 1418 | return KTextEditor::Cursor(virtualCursor.line(), thisLine.startCol()); | ||
1419 | } | 1419 | } | ||
1420 | 1420 | | |||
1421 | virtualLine = virtualCursor.line() - 1; | 1421 | virtualLine = virtualCursor.line() - 1; | ||
1422 | } | 1422 | } | ||
1423 | 1423 | | |||
1424 | currentOffset++; | 1424 | currentOffset++; | ||
1425 | 1425 | | |||
1426 | while (virtualLine >= 0 && virtualLine < (int)m_view->textFolding().visibleLines()) { | 1426 | while (virtualLine >= 0 && virtualLine < (int)view()->textFolding().visibleLines()) { | ||
1427 | int realLine = m_view->textFolding().visibleLineToLine(virtualLine); | 1427 | int realLine = view()->textFolding().visibleLineToLine(virtualLine); | ||
1428 | KateLineLayoutPtr thisLine = cache()->line(realLine, virtualLine); | 1428 | KateLineLayoutPtr thisLine = cache()->line(realLine, virtualLine); | ||
1429 | if (!thisLine) { | 1429 | if (!thisLine) { | ||
1430 | break; | 1430 | break; | ||
1431 | } | 1431 | } | ||
1432 | 1432 | | |||
1433 | for (int i = 0; i < thisLine->viewLineCount(); ++i) { | 1433 | for (int i = 0; i < thisLine->viewLineCount(); ++i) { | ||
1434 | if (offset == currentOffset) { | 1434 | if (offset == currentOffset) { | ||
1435 | KateTextLayout thisViewLine = thisLine->viewLine(i); | 1435 | KateTextLayout thisViewLine = thisLine->viewLine(i); | ||
1436 | 1436 | | |||
1437 | if (!forwards) { | 1437 | if (!forwards) { | ||
1438 | // We actually want it the other way around | 1438 | // We actually want it the other way around | ||
1439 | int requiredViewLine = cache()->lastViewLine(realLine) - thisViewLine.viewLine(); | 1439 | int requiredViewLine = cache()->lastViewLine(realLine) - thisViewLine.viewLine(); | ||
1440 | if (requiredViewLine != thisViewLine.viewLine()) { | 1440 | if (requiredViewLine != thisViewLine.viewLine()) { | ||
1441 | thisViewLine = thisLine->viewLine(requiredViewLine); | 1441 | thisViewLine = thisLine->viewLine(requiredViewLine); | ||
1442 | } | 1442 | } | ||
1443 | } | 1443 | } | ||
1444 | 1444 | | |||
1445 | KTextEditor::Cursor ret(virtualLine, thisViewLine.startCol()); | 1445 | KTextEditor::Cursor ret(virtualLine, thisViewLine.startCol()); | ||
1446 | 1446 | | |||
1447 | // keep column position | 1447 | // keep column position | ||
1448 | if (keepX) { | 1448 | if (keepX) { | ||
1449 | KTextEditor::Cursor realCursor = toRealCursor(virtualCursor); | 1449 | KTextEditor::Cursor realCursor = toRealCursor(virtualCursor); | ||
1450 | KateTextLayout t = cache()->textLayout(realCursor); | 1450 | KateTextLayout t = cache()->textLayout(realCursor); | ||
1451 | // renderer()->cursorToX(t, realCursor, !m_view->wrapCursor()); | 1451 | // renderer()->cursorToX(t, realCursor, !view()->wrapCursor()); | ||
1452 | 1452 | | |||
1453 | realCursor = renderer()->xToCursor(thisViewLine, m_preservedX, !m_view->wrapCursor()); | 1453 | realCursor = renderer()->xToCursor(thisViewLine, m_preservedX, !view()->wrapCursor()); | ||
1454 | ret.setColumn(realCursor.column()); | 1454 | ret.setColumn(realCursor.column()); | ||
1455 | } | 1455 | } | ||
1456 | 1456 | | |||
1457 | return ret; | 1457 | return ret; | ||
1458 | } | 1458 | } | ||
1459 | 1459 | | |||
1460 | currentOffset++; | 1460 | currentOffset++; | ||
1461 | } | 1461 | } | ||
1462 | 1462 | | |||
1463 | if (forwards) { | 1463 | if (forwards) { | ||
1464 | virtualLine++; | 1464 | virtualLine++; | ||
1465 | } else { | 1465 | } else { | ||
1466 | virtualLine--; | 1466 | virtualLine--; | ||
1467 | } | 1467 | } | ||
1468 | } | 1468 | } | ||
1469 | 1469 | | |||
1470 | // Looks like we were asked for something a bit exotic. | 1470 | // Looks like we were asked for something a bit exotic. | ||
1471 | // Return the max/min valid position. | 1471 | // Return the max/min valid position. | ||
1472 | if (forwards) { | 1472 | if (forwards) { | ||
1473 | return KTextEditor::Cursor(m_view->textFolding().visibleLines() - 1, doc()->lineLength(m_view->textFolding().visibleLineToLine(m_view->textFolding().visibleLines() - 1))); | 1473 | return KTextEditor::Cursor(view()->textFolding().visibleLines() - 1, doc()->lineLength(view()->textFolding().visibleLineToLine(view()->textFolding().visibleLines() - 1))); | ||
1474 | } else { | 1474 | } else { | ||
1475 | return KTextEditor::Cursor(0, 0); | 1475 | return KTextEditor::Cursor(0, 0); | ||
1476 | } | 1476 | } | ||
1477 | } | 1477 | } | ||
1478 | 1478 | | |||
1479 | int KateViewInternal::lineMaxCursorX(const KateTextLayout &range) | 1479 | int KateViewInternal::lineMaxCursorX(const KateTextLayout &range) | ||
1480 | { | 1480 | { | ||
1481 | if (!m_view->wrapCursor() && !range.wrap()) { | 1481 | if (!view()->wrapCursor() && !range.wrap()) { | ||
1482 | return INT_MAX; | 1482 | return INT_MAX; | ||
1483 | } | 1483 | } | ||
1484 | 1484 | | |||
1485 | int maxX = range.endX(); | 1485 | int maxX = range.endX(); | ||
1486 | 1486 | | |||
1487 | if (maxX && range.wrap()) { | 1487 | if (maxX && range.wrap()) { | ||
1488 | QChar lastCharInLine = doc()->kateTextLine(range.line())->at(range.endCol() - 1); | 1488 | QChar lastCharInLine = doc()->kateTextLine(range.line())->at(range.endCol() - 1); | ||
1489 | maxX -= renderer()->config()->fontMetrics().width(lastCharInLine); | 1489 | maxX -= renderer()->config()->fontMetrics().width(lastCharInLine); | ||
Show All 10 Lines | 1499 | if (maxCol && range.wrap()) { | |||
1500 | maxCol--; | 1500 | maxCol--; | ||
1501 | } | 1501 | } | ||
1502 | 1502 | | |||
1503 | return maxCol; | 1503 | return maxCol; | ||
1504 | } | 1504 | } | ||
1505 | 1505 | | |||
1506 | void KateViewInternal::cursorUp(bool sel) | 1506 | void KateViewInternal::cursorUp(bool sel) | ||
1507 | { | 1507 | { | ||
1508 | if (!sel && m_view->completionWidget()->isCompletionActive()) { | 1508 | if (!sel && view()->completionWidget()->isCompletionActive()) { | ||
1509 | m_view->completionWidget()->cursorUp(); | 1509 | view()->completionWidget()->cursorUp(); | ||
1510 | return; | 1510 | return; | ||
1511 | } | 1511 | } | ||
1512 | 1512 | | |||
1513 | // assert that the display cursor is in visible lines | 1513 | // assert that the display cursor is in visible lines | ||
1514 | Q_ASSERT(m_displayCursor.line() < m_view->textFolding().visibleLines()); | 1514 | Q_ASSERT(m_displayCursor.line() < view()->textFolding().visibleLines()); | ||
1515 | 1515 | | |||
1516 | /** | 1516 | /** | ||
1517 | * move cursor to start of line, if we are at first line! | 1517 | * move cursor to start of line, if we are at first line! | ||
1518 | */ | 1518 | */ | ||
1519 | if (m_displayCursor.line() == 0 && (!m_view->dynWordWrap() || cache()->viewLine(m_cursor) == 0)) { | 1519 | if (m_displayCursor.line() == 0 && (!view()->dynWordWrap() || cache()->viewLine(m_cursor) == 0)) { | ||
1520 | home(sel); | 1520 | home(sel); | ||
1521 | return; | 1521 | return; | ||
1522 | } | 1522 | } | ||
1523 | 1523 | | |||
1524 | m_preserveX = true; | 1524 | m_preserveX = true; | ||
1525 | 1525 | | |||
1526 | KateTextLayout thisLine = currentLayout(); | 1526 | KateTextLayout thisLine = currentLayout(); | ||
1527 | // This is not the first line because that is already simplified out above | 1527 | // This is not the first line because that is already simplified out above | ||
1528 | KateTextLayout pRange = previousLayout(); | 1528 | KateTextLayout pRange = previousLayout(); | ||
1529 | 1529 | | |||
1530 | // Ensure we're in the right spot | 1530 | // Ensure we're in the right spot | ||
1531 | Q_ASSERT(m_cursor.line() == thisLine.line()); | 1531 | Q_ASSERT(m_cursor.line() == thisLine.line()); | ||
1532 | Q_ASSERT(m_cursor.column() >= thisLine.startCol()); | 1532 | Q_ASSERT(m_cursor.column() >= thisLine.startCol()); | ||
1533 | Q_ASSERT(!thisLine.wrap() || m_cursor.column() < thisLine.endCol()); | 1533 | Q_ASSERT(!thisLine.wrap() || m_cursor.column() < thisLine.endCol()); | ||
1534 | 1534 | | |||
1535 | KTextEditor::Cursor c = renderer()->xToCursor(pRange, m_preservedX, !m_view->wrapCursor()); | 1535 | KTextEditor::Cursor c = renderer()->xToCursor(pRange, m_preservedX, !view()->wrapCursor()); | ||
1536 | 1536 | | |||
1537 | updateSelection(c, sel); | 1537 | updateSelection(c, sel); | ||
1538 | updateCursor(c); | 1538 | updateCursor(c); | ||
1539 | } | 1539 | } | ||
1540 | 1540 | | |||
1541 | void KateViewInternal::cursorDown(bool sel) | 1541 | void KateViewInternal::cursorDown(bool sel) | ||
1542 | { | 1542 | { | ||
1543 | if (!sel && m_view->completionWidget()->isCompletionActive()) { | 1543 | if (!sel && view()->completionWidget()->isCompletionActive()) { | ||
1544 | m_view->completionWidget()->cursorDown(); | 1544 | view()->completionWidget()->cursorDown(); | ||
1545 | return; | 1545 | return; | ||
1546 | } | 1546 | } | ||
1547 | 1547 | | |||
1548 | /** | 1548 | /** | ||
1549 | * move cursor to end of line, if we are at last line! | 1549 | * move cursor to end of line, if we are at last line! | ||
1550 | */ | 1550 | */ | ||
1551 | if ((m_displayCursor.line() >= m_view->textFolding().visibleLines() - 1) && (!m_view->dynWordWrap() || cache()->viewLine(m_cursor) == cache()->lastViewLine(m_cursor.line()))) { | 1551 | if ((m_displayCursor.line() >= view()->textFolding().visibleLines() - 1) && (!view()->dynWordWrap() || cache()->viewLine(m_cursor) == cache()->lastViewLine(m_cursor.line()))) { | ||
1552 | end(sel); | 1552 | end(sel); | ||
1553 | return; | 1553 | return; | ||
1554 | } | 1554 | } | ||
1555 | 1555 | | |||
1556 | m_preserveX = true; | 1556 | m_preserveX = true; | ||
1557 | 1557 | | |||
1558 | KateTextLayout thisLine = currentLayout(); | 1558 | KateTextLayout thisLine = currentLayout(); | ||
1559 | // This is not the last line because that is already simplified out above | 1559 | // This is not the last line because that is already simplified out above | ||
1560 | KateTextLayout nRange = nextLayout(); | 1560 | KateTextLayout nRange = nextLayout(); | ||
1561 | 1561 | | |||
1562 | // Ensure we're in the right spot | 1562 | // Ensure we're in the right spot | ||
1563 | Q_ASSERT((m_cursor.line() == thisLine.line()) && | 1563 | Q_ASSERT((m_cursor.line() == thisLine.line()) && | ||
1564 | (m_cursor.column() >= thisLine.startCol()) && | 1564 | (m_cursor.column() >= thisLine.startCol()) && | ||
1565 | (!thisLine.wrap() || m_cursor.column() < thisLine.endCol())); | 1565 | (!thisLine.wrap() || m_cursor.column() < thisLine.endCol())); | ||
1566 | 1566 | | |||
1567 | KTextEditor::Cursor c = renderer()->xToCursor(nRange, m_preservedX, !m_view->wrapCursor()); | 1567 | KTextEditor::Cursor c = renderer()->xToCursor(nRange, m_preservedX, !view()->wrapCursor()); | ||
1568 | 1568 | | |||
1569 | updateSelection(c, sel); | 1569 | updateSelection(c, sel); | ||
1570 | updateCursor(c); | 1570 | updateCursor(c); | ||
1571 | } | 1571 | } | ||
1572 | 1572 | | |||
1573 | void KateViewInternal::cursorToMatchingBracket(bool sel) | 1573 | void KateViewInternal::cursorToMatchingBracket(bool sel) | ||
1574 | { | 1574 | { | ||
1575 | KTextEditor::Cursor c = findMatchingBracket(); | 1575 | KTextEditor::Cursor c = findMatchingBracket(); | ||
Show All 19 Lines | |||||
1595 | } | 1595 | } | ||
1596 | 1596 | | |||
1597 | // lines is the offset to scroll by | 1597 | // lines is the offset to scroll by | ||
1598 | void KateViewInternal::scrollLines(int lines, bool sel) | 1598 | void KateViewInternal::scrollLines(int lines, bool sel) | ||
1599 | { | 1599 | { | ||
1600 | KTextEditor::Cursor c = viewLineOffset(m_displayCursor, lines, true); | 1600 | KTextEditor::Cursor c = viewLineOffset(m_displayCursor, lines, true); | ||
1601 | 1601 | | |||
1602 | // Fix the virtual cursor -> real cursor | 1602 | // Fix the virtual cursor -> real cursor | ||
1603 | c.setLine(m_view->textFolding().visibleLineToLine(c.line())); | 1603 | c.setLine(view()->textFolding().visibleLineToLine(c.line())); | ||
1604 | 1604 | | |||
1605 | updateSelection(c, sel); | 1605 | updateSelection(c, sel); | ||
1606 | updateCursor(c); | 1606 | updateCursor(c); | ||
1607 | } | 1607 | } | ||
1608 | 1608 | | |||
1609 | // This is a bit misleading... it's asking for the view to be scrolled, not the cursor | 1609 | // This is a bit misleading... it's asking for the view to be scrolled, not the cursor | ||
1610 | void KateViewInternal::scrollUp() | 1610 | void KateViewInternal::scrollUp() | ||
1611 | { | 1611 | { | ||
Show All 13 Lines | 1623 | { | |||
1625 | m_minLinesVisible = qMin(int((linesDisplayed() - 1) / 2), m_autoCenterLines); | 1625 | m_minLinesVisible = qMin(int((linesDisplayed() - 1) / 2), m_autoCenterLines); | ||
1626 | if (updateView) { | 1626 | if (updateView) { | ||
1627 | KateViewInternal::updateView(); | 1627 | KateViewInternal::updateView(); | ||
1628 | } | 1628 | } | ||
1629 | } | 1629 | } | ||
1630 | 1630 | | |||
1631 | void KateViewInternal::pageUp(bool sel, bool half) | 1631 | void KateViewInternal::pageUp(bool sel, bool half) | ||
1632 | { | 1632 | { | ||
1633 | if (m_view->isCompletionActive()) { | 1633 | if (view()->isCompletionActive()) { | ||
1634 | m_view->completionWidget()->pageUp(); | 1634 | view()->completionWidget()->pageUp(); | ||
1635 | return; | 1635 | return; | ||
1636 | } | 1636 | } | ||
1637 | 1637 | | |||
1638 | // remember the view line and x pos | 1638 | // remember the view line and x pos | ||
1639 | int viewLine = cache()->displayViewLine(m_displayCursor); | 1639 | int viewLine = cache()->displayViewLine(m_displayCursor); | ||
1640 | bool atTop = startPos().atStartOfDocument(); | 1640 | bool atTop = startPos().atStartOfDocument(); | ||
1641 | 1641 | | |||
1642 | // Adjust for an auto-centering cursor | 1642 | // Adjust for an auto-centering cursor | ||
Show All 12 Lines | 1654 | if (!doc()->pageUpDownMovesCursor() && !atTop) { | |||
1655 | KTextEditor::Cursor newStartPos = viewLineOffset(startPos(), linesToScroll - 1); | 1655 | KTextEditor::Cursor newStartPos = viewLineOffset(startPos(), linesToScroll - 1); | ||
1656 | scrollPos(newStartPos); | 1656 | scrollPos(newStartPos); | ||
1657 | 1657 | | |||
1658 | // put the cursor back approximately where it was | 1658 | // put the cursor back approximately where it was | ||
1659 | KTextEditor::Cursor newPos = toRealCursor(viewLineOffset(newStartPos, viewLine, true)); | 1659 | KTextEditor::Cursor newPos = toRealCursor(viewLineOffset(newStartPos, viewLine, true)); | ||
1660 | 1660 | | |||
1661 | KateTextLayout newLine = cache()->textLayout(newPos); | 1661 | KateTextLayout newLine = cache()->textLayout(newPos); | ||
1662 | 1662 | | |||
1663 | newPos = renderer()->xToCursor(newLine, m_preservedX, !m_view->wrapCursor()); | 1663 | newPos = renderer()->xToCursor(newLine, m_preservedX, !view()->wrapCursor()); | ||
1664 | 1664 | | |||
1665 | m_preserveX = true; | 1665 | m_preserveX = true; | ||
1666 | updateSelection(newPos, sel); | 1666 | updateSelection(newPos, sel); | ||
1667 | updateCursor(newPos); | 1667 | updateCursor(newPos); | ||
1668 | 1668 | | |||
1669 | } else { | 1669 | } else { | ||
1670 | scrollLines(linesToScroll, sel); | 1670 | scrollLines(linesToScroll, sel); | ||
1671 | } | 1671 | } | ||
1672 | } | 1672 | } | ||
1673 | 1673 | | |||
1674 | void KateViewInternal::pageDown(bool sel, bool half) | 1674 | void KateViewInternal::pageDown(bool sel, bool half) | ||
1675 | { | 1675 | { | ||
1676 | if (m_view->isCompletionActive()) { | 1676 | if (view()->isCompletionActive()) { | ||
1677 | m_view->completionWidget()->pageDown(); | 1677 | view()->completionWidget()->pageDown(); | ||
1678 | return; | 1678 | return; | ||
1679 | } | 1679 | } | ||
1680 | 1680 | | |||
1681 | // remember the view line | 1681 | // remember the view line | ||
1682 | int viewLine = cache()->displayViewLine(m_displayCursor); | 1682 | int viewLine = cache()->displayViewLine(m_displayCursor); | ||
1683 | bool atEnd = startPos() >= m_cachedMaxStartPos; | 1683 | bool atEnd = startPos() >= m_cachedMaxStartPos; | ||
1684 | 1684 | | |||
1685 | // Adjust for an auto-centering cursor | 1685 | // Adjust for an auto-centering cursor | ||
Show All 12 Lines | 1697 | if (!doc()->pageUpDownMovesCursor() && !atEnd) { | |||
1698 | KTextEditor::Cursor newStartPos = viewLineOffset(startPos(), linesToScroll + 1); | 1698 | KTextEditor::Cursor newStartPos = viewLineOffset(startPos(), linesToScroll + 1); | ||
1699 | scrollPos(newStartPos); | 1699 | scrollPos(newStartPos); | ||
1700 | 1700 | | |||
1701 | // put the cursor back approximately where it was | 1701 | // put the cursor back approximately where it was | ||
1702 | KTextEditor::Cursor newPos = toRealCursor(viewLineOffset(newStartPos, viewLine, true)); | 1702 | KTextEditor::Cursor newPos = toRealCursor(viewLineOffset(newStartPos, viewLine, true)); | ||
1703 | 1703 | | |||
1704 | KateTextLayout newLine = cache()->textLayout(newPos); | 1704 | KateTextLayout newLine = cache()->textLayout(newPos); | ||
1705 | 1705 | | |||
1706 | newPos = renderer()->xToCursor(newLine, m_preservedX, !m_view->wrapCursor()); | 1706 | newPos = renderer()->xToCursor(newLine, m_preservedX, !view()->wrapCursor()); | ||
1707 | 1707 | | |||
1708 | m_preserveX = true; | 1708 | m_preserveX = true; | ||
1709 | updateSelection(newPos, sel); | 1709 | updateSelection(newPos, sel); | ||
1710 | updateCursor(newPos); | 1710 | updateCursor(newPos); | ||
1711 | 1711 | | |||
1712 | } else { | 1712 | } else { | ||
1713 | scrollLines(linesToScroll, sel); | 1713 | scrollLines(linesToScroll, sel); | ||
1714 | } | 1714 | } | ||
1715 | } | 1715 | } | ||
1716 | 1716 | | |||
1717 | int KateViewInternal::maxLen(int startLine) | 1717 | int KateViewInternal::maxLen(int startLine) | ||
1718 | { | 1718 | { | ||
1719 | Q_ASSERT(!m_view->dynWordWrap()); | 1719 | Q_ASSERT(!view()->dynWordWrap()); | ||
1720 | 1720 | | |||
1721 | int displayLines = (m_view->height() / renderer()->lineHeight()) + 1; | 1721 | int displayLines = (view()->height() / renderer()->lineHeight()) + 1; | ||
1722 | 1722 | | |||
1723 | int maxLen = 0; | 1723 | int maxLen = 0; | ||
1724 | 1724 | | |||
1725 | for (int z = 0; z < displayLines; z++) { | 1725 | for (int z = 0; z < displayLines; z++) { | ||
1726 | int virtualLine = startLine + z; | 1726 | int virtualLine = startLine + z; | ||
1727 | 1727 | | |||
1728 | if (virtualLine < 0 || virtualLine >= (int)m_view->textFolding().visibleLines()) { | 1728 | if (virtualLine < 0 || virtualLine >= (int)view()->textFolding().visibleLines()) { | ||
1729 | break; | 1729 | break; | ||
1730 | } | 1730 | } | ||
1731 | 1731 | | |||
1732 | maxLen = qMax(maxLen, cache()->line(m_view->textFolding().visibleLineToLine(virtualLine))->width()); | 1732 | maxLen = qMax(maxLen, cache()->line(view()->textFolding().visibleLineToLine(virtualLine))->width()); | ||
1733 | } | 1733 | } | ||
1734 | 1734 | | |||
1735 | return maxLen; | 1735 | return maxLen; | ||
1736 | } | 1736 | } | ||
1737 | 1737 | | |||
1738 | bool KateViewInternal::columnScrollingPossible() | 1738 | bool KateViewInternal::columnScrollingPossible() | ||
1739 | { | 1739 | { | ||
1740 | return !m_view->dynWordWrap() && m_columnScroll->isEnabled() && (m_columnScroll->maximum() > 0); | 1740 | return !view()->dynWordWrap() && m_columnScroll->isEnabled() && (m_columnScroll->maximum() > 0); | ||
1741 | } | 1741 | } | ||
1742 | 1742 | | |||
1743 | bool KateViewInternal::lineScrollingPossible() | 1743 | bool KateViewInternal::lineScrollingPossible() | ||
1744 | { | 1744 | { | ||
1745 | return m_lineScroll->minimum() != m_lineScroll->maximum(); | 1745 | return m_lineScroll->minimum() != m_lineScroll->maximum(); | ||
1746 | } | 1746 | } | ||
1747 | 1747 | | |||
1748 | void KateViewInternal::top(bool sel) | 1748 | void KateViewInternal::top(bool sel) | ||
1749 | { | 1749 | { | ||
1750 | KTextEditor::Cursor newCursor(0, 0); | 1750 | KTextEditor::Cursor newCursor(0, 0); | ||
1751 | 1751 | | |||
1752 | newCursor = renderer()->xToCursor(cache()->textLayout(newCursor), m_preservedX, !m_view->wrapCursor()); | 1752 | newCursor = renderer()->xToCursor(cache()->textLayout(newCursor), m_preservedX, !view()->wrapCursor()); | ||
1753 | 1753 | | |||
1754 | updateSelection(newCursor, sel); | 1754 | updateSelection(newCursor, sel); | ||
1755 | updateCursor(newCursor); | 1755 | updateCursor(newCursor); | ||
1756 | } | 1756 | } | ||
1757 | 1757 | | |||
1758 | void KateViewInternal::bottom(bool sel) | 1758 | void KateViewInternal::bottom(bool sel) | ||
1759 | { | 1759 | { | ||
1760 | KTextEditor::Cursor newCursor(doc()->lastLine(), 0); | 1760 | KTextEditor::Cursor newCursor(doc()->lastLine(), 0); | ||
1761 | 1761 | | |||
1762 | newCursor = renderer()->xToCursor(cache()->textLayout(newCursor), m_preservedX, !m_view->wrapCursor()); | 1762 | newCursor = renderer()->xToCursor(cache()->textLayout(newCursor), m_preservedX, !view()->wrapCursor()); | ||
1763 | 1763 | | |||
1764 | updateSelection(newCursor, sel); | 1764 | updateSelection(newCursor, sel); | ||
1765 | updateCursor(newCursor); | 1765 | updateCursor(newCursor); | ||
1766 | } | 1766 | } | ||
1767 | 1767 | | |||
1768 | void KateViewInternal::top_home(bool sel) | 1768 | void KateViewInternal::top_home(bool sel) | ||
1769 | { | 1769 | { | ||
1770 | if (m_view->isCompletionActive()) { | 1770 | if (view()->isCompletionActive()) { | ||
1771 | m_view->completionWidget()->top(); | 1771 | view()->completionWidget()->top(); | ||
1772 | return; | 1772 | return; | ||
1773 | } | 1773 | } | ||
1774 | 1774 | | |||
1775 | KTextEditor::Cursor c(0, 0); | 1775 | KTextEditor::Cursor c(0, 0); | ||
1776 | updateSelection(c, sel); | 1776 | updateSelection(c, sel); | ||
1777 | updateCursor(c); | 1777 | updateCursor(c); | ||
1778 | } | 1778 | } | ||
1779 | 1779 | | |||
1780 | void KateViewInternal::bottom_end(bool sel) | 1780 | void KateViewInternal::bottom_end(bool sel) | ||
1781 | { | 1781 | { | ||
1782 | if (m_view->isCompletionActive()) { | 1782 | if (view()->isCompletionActive()) { | ||
1783 | m_view->completionWidget()->bottom(); | 1783 | view()->completionWidget()->bottom(); | ||
1784 | return; | 1784 | return; | ||
1785 | } | 1785 | } | ||
1786 | 1786 | | |||
1787 | KTextEditor::Cursor c(doc()->lastLine(), doc()->lineLength(doc()->lastLine())); | 1787 | KTextEditor::Cursor c(doc()->lastLine(), doc()->lineLength(doc()->lastLine())); | ||
1788 | updateSelection(c, sel); | 1788 | updateSelection(c, sel); | ||
1789 | updateCursor(c); | 1789 | updateCursor(c); | ||
1790 | } | 1790 | } | ||
1791 | 1791 | | |||
1792 | void KateViewInternal::updateSelection(const KTextEditor::Cursor &_newCursor, bool keepSel) | 1792 | void KateViewInternal::updateSelection(const KTextEditor::Cursor &_newCursor, bool keepSel) | ||
1793 | { | 1793 | { | ||
1794 | KTextEditor::Cursor newCursor = _newCursor; | 1794 | KTextEditor::Cursor newCursor = _newCursor; | ||
1795 | if (keepSel) { | 1795 | if (keepSel) { | ||
1796 | if (!m_view->selection() || (m_selectAnchor.line() == -1) | 1796 | if (!view()->selection() || (m_selectAnchor.line() == -1) | ||
1797 | //don't kill the selection if we have a persistent selection and | 1797 | //don't kill the selection if we have a persistent selection and | ||
1798 | //the cursor is inside or at the boundaries of the selected area | 1798 | //the cursor is inside or at the boundaries of the selected area | ||
1799 | || (m_view->config()->persistentSelection() | 1799 | || (view()->config()->persistentSelection() | ||
1800 | && !(m_view->selectionRange().contains(m_cursor) | 1800 | && !(view()->selectionRange().contains(m_cursor) | ||
1801 | || m_view->selectionRange().boundaryAtCursor(m_cursor)))) { | 1801 | || view()->selectionRange().boundaryAtCursor(m_cursor)))) { | ||
1802 | m_selectAnchor = m_cursor; | 1802 | m_selectAnchor = m_cursor; | ||
1803 | setSelection(KTextEditor::Range(m_cursor, newCursor)); | 1803 | setSelection(KTextEditor::Range(m_cursor, newCursor)); | ||
1804 | } else { | 1804 | } else { | ||
1805 | bool doSelect = true; | 1805 | bool doSelect = true; | ||
1806 | switch (m_selectionMode) { | 1806 | switch (m_selectionMode) { | ||
1807 | case Word: { | 1807 | case Word: { | ||
1808 | // Restore selStartCached if needed. It gets nuked by | 1808 | // Restore selStartCached if needed. It gets nuked by | ||
1809 | // viewSelectionChanged if we drag the selection into non-existence, | 1809 | // viewSelectionChanged if we drag the selection into non-existence, | ||
▲ Show 20 Lines • Show All 90 Lines • ▼ Show 20 Line(s) | |||||
1900 | if (doSelect) { | 1900 | if (doSelect) { | ||
1901 | setSelection(KTextEditor::Range(m_selectAnchor, newCursor)); | 1901 | setSelection(KTextEditor::Range(m_selectAnchor, newCursor)); | ||
1902 | } else if (m_selectionCached.isValid()) { // we have a cached selection, so we restore that | 1902 | } else if (m_selectionCached.isValid()) { // we have a cached selection, so we restore that | ||
1903 | setSelection(m_selectionCached); | 1903 | setSelection(m_selectionCached); | ||
1904 | } | 1904 | } | ||
1905 | } | 1905 | } | ||
1906 | 1906 | | |||
1907 | m_selChangedByUser = true; | 1907 | m_selChangedByUser = true; | ||
1908 | } else if (!m_view->config()->persistentSelection()) { | 1908 | } else if (!view()->config()->persistentSelection()) { | ||
1909 | m_view->clearSelection(); | 1909 | view()->clearSelection(); | ||
1910 | 1910 | | |||
1911 | m_selectionCached = KTextEditor::Range::invalid(); | 1911 | m_selectionCached = KTextEditor::Range::invalid(); | ||
1912 | m_selectAnchor = KTextEditor::Cursor::invalid(); | 1912 | m_selectAnchor = KTextEditor::Cursor::invalid(); | ||
1913 | } | 1913 | } | ||
1914 | 1914 | | |||
1915 | #ifndef QT_NO_ACCESSIBILITY | 1915 | #ifndef QT_NO_ACCESSIBILITY | ||
1916 | // FIXME KF5 | 1916 | // FIXME KF5 | ||
1917 | // QAccessibleTextSelectionEvent ev(this, /* selection start, selection end*/); | 1917 | // QAccessibleTextSelectionEvent ev(this, /* selection start, selection end*/); | ||
1918 | // QAccessible::updateAccessibility(&ev); | 1918 | // QAccessible::updateAccessibility(&ev); | ||
1919 | #endif | 1919 | #endif | ||
1920 | } | 1920 | } | ||
1921 | 1921 | | |||
1922 | void KateViewInternal::setSelection(const KTextEditor::Range &range) | 1922 | void KateViewInternal::setSelection(const KTextEditor::Range &range) | ||
1923 | { | 1923 | { | ||
1924 | disconnect(m_view, SIGNAL(selectionChanged(KTextEditor::View*)), this, SLOT(viewSelectionChanged())); | 1924 | disconnect(m_view, SIGNAL(selectionChanged(KTextEditor::View*)), this, SLOT(viewSelectionChanged())); | ||
1925 | m_view->setSelection(range); | 1925 | view()->setSelection(range); | ||
1926 | connect(m_view, SIGNAL(selectionChanged(KTextEditor::View*)), this, SLOT(viewSelectionChanged())); | 1926 | connect(m_view, SIGNAL(selectionChanged(KTextEditor::View*)), this, SLOT(viewSelectionChanged())); | ||
1927 | } | 1927 | } | ||
1928 | 1928 | | |||
1929 | void KateViewInternal::moveCursorToSelectionEdge() | 1929 | void KateViewInternal::moveCursorToSelectionEdge() | ||
1930 | { | 1930 | { | ||
1931 | if (!m_view->selection()) { | 1931 | if (!view()->selection()) { | ||
1932 | return; | 1932 | return; | ||
1933 | } | 1933 | } | ||
1934 | 1934 | | |||
1935 | int tmp = m_minLinesVisible; | 1935 | int tmp = m_minLinesVisible; | ||
1936 | m_minLinesVisible = 0; | 1936 | m_minLinesVisible = 0; | ||
1937 | 1937 | | |||
1938 | if (m_view->selectionRange().start() < m_selectAnchor) { | 1938 | if (view()->selectionRange().start() < m_selectAnchor) { | ||
1939 | updateCursor(m_view->selectionRange().start()); | 1939 | updateCursor(view()->selectionRange().start()); | ||
1940 | } else { | 1940 | } else { | ||
1941 | updateCursor(m_view->selectionRange().end()); | 1941 | updateCursor(view()->selectionRange().end()); | ||
1942 | } | 1942 | } | ||
1943 | 1943 | | |||
1944 | m_minLinesVisible = tmp; | 1944 | m_minLinesVisible = tmp; | ||
1945 | } | 1945 | } | ||
1946 | 1946 | | |||
1947 | void KateViewInternal::updateCursor(const KTextEditor::Cursor &newCursor, bool force, bool center, bool calledExternally) | 1947 | void KateViewInternal::updateCursor(const KTextEditor::Cursor &newCursor, bool force, bool center, bool calledExternally) | ||
1948 | { | 1948 | { | ||
1949 | if (!force && (m_cursor.toCursor() == newCursor)) { | 1949 | if (!force && (m_cursor.toCursor() == newCursor)) { | ||
1950 | m_displayCursor = toVirtualCursor(newCursor); | 1950 | m_displayCursor = toVirtualCursor(newCursor); | ||
1951 | if (!m_madeVisible && m_view == doc()->activeView()) { | 1951 | if (!m_madeVisible && m_view == doc()->activeView()) { | ||
1952 | // unfold if required | 1952 | // unfold if required | ||
1953 | m_view->textFolding().ensureLineIsVisible(newCursor.line()); | 1953 | view()->textFolding().ensureLineIsVisible(newCursor.line()); | ||
1954 | 1954 | | |||
1955 | makeVisible(m_displayCursor, m_displayCursor.column(), false, center, calledExternally); | 1955 | makeVisible(m_displayCursor, m_displayCursor.column(), false, center, calledExternally); | ||
1956 | } | 1956 | } | ||
1957 | 1957 | | |||
1958 | return; | 1958 | return; | ||
1959 | } | 1959 | } | ||
1960 | 1960 | | |||
1961 | if (m_cursor.line() != newCursor.line()) { | 1961 | if (m_cursor.line() != newCursor.line()) { | ||
1962 | m_leftBorder->updateForCursorLineChange(); | 1962 | m_leftBorder->updateForCursorLineChange(); | ||
1963 | } | 1963 | } | ||
1964 | 1964 | | |||
1965 | // unfold if required | 1965 | // unfold if required | ||
1966 | m_view->textFolding().ensureLineIsVisible(newCursor.line()); | 1966 | view()->textFolding().ensureLineIsVisible(newCursor.line()); | ||
1967 | 1967 | | |||
1968 | KTextEditor::Cursor oldDisplayCursor = m_displayCursor; | 1968 | KTextEditor::Cursor oldDisplayCursor = m_displayCursor; | ||
1969 | 1969 | | |||
1970 | m_displayCursor = toVirtualCursor(newCursor); | 1970 | m_displayCursor = toVirtualCursor(newCursor); | ||
1971 | m_cursor.setPosition(newCursor); | 1971 | m_cursor.setPosition(newCursor); | ||
1972 | 1972 | | |||
1973 | if (m_view == doc()->activeView()) { | 1973 | if (m_view == doc()->activeView()) { | ||
1974 | makeVisible(m_displayCursor, m_displayCursor.column(), false, center, calledExternally); | 1974 | makeVisible(m_displayCursor, m_displayCursor.column(), false, center, calledExternally); | ||
Show All 15 Lines | 1987 | if (m_cursorTimer.isActive()) { | |||
1990 | } | 1990 | } | ||
1991 | renderer()->setDrawCaret(true); | 1991 | renderer()->setDrawCaret(true); | ||
1992 | } | 1992 | } | ||
1993 | 1993 | | |||
1994 | // Remember the maximum X position if requested | 1994 | // Remember the maximum X position if requested | ||
1995 | if (m_preserveX) { | 1995 | if (m_preserveX) { | ||
1996 | m_preserveX = false; | 1996 | m_preserveX = false; | ||
1997 | } else { | 1997 | } else { | ||
1998 | m_preservedX = renderer()->cursorToX(cache()->textLayout(m_cursor), m_cursor, !m_view->wrapCursor()); | 1998 | m_preservedX = renderer()->cursorToX(cache()->textLayout(m_cursor), m_cursor, !view()->wrapCursor()); | ||
1999 | } | 1999 | } | ||
2000 | 2000 | | |||
2001 | //qCDebug(LOG_KTE) << "m_preservedX: " << m_preservedX << " (was "<< oldmaxx << "), m_cursorX: " << m_cursorX; | 2001 | //qCDebug(LOG_KTE) << "m_preservedX: " << m_preservedX << " (was "<< oldmaxx << "), m_cursorX: " << m_cursorX; | ||
2002 | //qCDebug(LOG_KTE) << "Cursor now located at real " << cursor.line << "," << cursor.col << ", virtual " << m_displayCursor.line << ", " << m_displayCursor.col << "; Top is " << startLine() << ", " << startPos().col; | 2002 | //qCDebug(LOG_KTE) << "Cursor now located at real " << cursor.line << "," << cursor.col << ", virtual " << m_displayCursor.line << ", " << m_displayCursor.col << "; Top is " << startLine() << ", " << startPos().col; | ||
2003 | 2003 | | |||
2004 | cursorMoved(); | 2004 | cursorMoved(); | ||
2005 | 2005 | | |||
2006 | updateDirty(); //paintText(0, 0, width(), height(), true); | 2006 | updateDirty(); //paintText(0, 0, width(), height(), true); | ||
2007 | 2007 | | |||
2008 | emit m_view->cursorPositionChanged(m_view, m_cursor); | 2008 | emit view()->cursorPositionChanged(m_view, m_cursor); | ||
2009 | } | 2009 | } | ||
2010 | 2010 | | |||
2011 | void KateViewInternal::updateBracketMarkAttributes() | 2011 | void KateViewInternal::updateBracketMarkAttributes() | ||
2012 | { | 2012 | { | ||
2013 | KTextEditor::Attribute::Ptr bracketFill = KTextEditor::Attribute::Ptr(new KTextEditor::Attribute()); | 2013 | KTextEditor::Attribute::Ptr bracketFill = KTextEditor::Attribute::Ptr(new KTextEditor::Attribute()); | ||
2014 | bracketFill->setBackground(m_view->m_renderer->config()->highlightedBracketColor()); | 2014 | bracketFill->setBackground(view()->m_renderer->config()->highlightedBracketColor()); | ||
2015 | bracketFill->setBackgroundFillWhitespace(false); | 2015 | bracketFill->setBackgroundFillWhitespace(false); | ||
2016 | if (QFontInfo(renderer()->currentFont()).fixedPitch()) { | 2016 | if (QFontInfo(renderer()->currentFont()).fixedPitch()) { | ||
2017 | // make font bold only for fixed fonts, otherwise text jumps around | 2017 | // make font bold only for fixed fonts, otherwise text jumps around | ||
2018 | bracketFill->setFontBold(); | 2018 | bracketFill->setFontBold(); | ||
2019 | } | 2019 | } | ||
2020 | 2020 | | |||
2021 | m_bmStart->setAttribute(bracketFill); | 2021 | m_bmStart->setAttribute(bracketFill); | ||
2022 | m_bmEnd->setAttribute(bracketFill); | 2022 | m_bmEnd->setAttribute(bracketFill); | ||
2023 | 2023 | | |||
2024 | if (m_view->m_renderer->config()->showWholeBracketExpression()) { | 2024 | if (view()->m_renderer->config()->showWholeBracketExpression()) { | ||
2025 | KTextEditor::Attribute::Ptr expressionFill = KTextEditor::Attribute::Ptr(new KTextEditor::Attribute()); | 2025 | KTextEditor::Attribute::Ptr expressionFill = KTextEditor::Attribute::Ptr(new KTextEditor::Attribute()); | ||
2026 | expressionFill->setBackground(m_view->m_renderer->config()->highlightedBracketColor()); | 2026 | expressionFill->setBackground(view()->m_renderer->config()->highlightedBracketColor()); | ||
2027 | expressionFill->setBackgroundFillWhitespace(false); | 2027 | expressionFill->setBackgroundFillWhitespace(false); | ||
2028 | 2028 | | |||
2029 | m_bm->setAttribute(expressionFill); | 2029 | m_bm->setAttribute(expressionFill); | ||
2030 | } else { | 2030 | } else { | ||
2031 | m_bm->setAttribute(KTextEditor::Attribute::Ptr(new KTextEditor::Attribute())); | 2031 | m_bm->setAttribute(KTextEditor::Attribute::Ptr(new KTextEditor::Attribute())); | ||
2032 | } | 2032 | } | ||
2033 | } | 2033 | } | ||
2034 | 2034 | | |||
Show All 20 Lines | 2042 | if (newRange.isValid()) { | |||
2055 | if (!renderer()->config()->animateBracketMatching()) { | 2055 | if (!renderer()->config()->animateBracketMatching()) { | ||
2056 | return; | 2056 | return; | ||
2057 | } | 2057 | } | ||
2058 | const KTextEditor::Cursor flashPos = (m_cursor == m_bmStart->start() || m_cursor == m_bmStart->end()) ? m_bmEnd->start() : m_bm->start(); | 2058 | const KTextEditor::Cursor flashPos = (m_cursor == m_bmStart->start() || m_cursor == m_bmStart->end()) ? m_bmEnd->start() : m_bm->start(); | ||
2059 | if (flashPos != m_bmLastFlashPos->toCursor()) { | 2059 | if (flashPos != m_bmLastFlashPos->toCursor()) { | ||
2060 | m_bmLastFlashPos->setPosition(flashPos); | 2060 | m_bmLastFlashPos->setPosition(flashPos); | ||
2061 | 2061 | | |||
2062 | KTextEditor::Attribute::Ptr attribute = doc()->attributeAt(flashPos); | 2062 | KTextEditor::Attribute::Ptr attribute = doc()->attributeAt(flashPos); | ||
2063 | attribute->setBackground(m_view->m_renderer->config()->highlightedBracketColor()); | 2063 | attribute->setBackground(view()->m_renderer->config()->highlightedBracketColor()); | ||
2064 | attribute->setFontBold(m_bmStart->attribute()->fontBold()); | 2064 | attribute->setFontBold(m_bmStart->attribute()->fontBold()); | ||
2065 | 2065 | | |||
2066 | flashChar(flashPos, attribute); | 2066 | flashChar(flashPos, attribute); | ||
2067 | } | 2067 | } | ||
2068 | return; | 2068 | return; | ||
2069 | } | 2069 | } | ||
2070 | 2070 | | |||
2071 | // new range was invalid | 2071 | // new range was invalid | ||
2072 | m_bm->setRange(KTextEditor::Range::invalid()); | 2072 | m_bm->setRange(KTextEditor::Range::invalid()); | ||
2073 | m_bmStart->setRange(KTextEditor::Range::invalid()); | 2073 | m_bmStart->setRange(KTextEditor::Range::invalid()); | ||
2074 | m_bmEnd->setRange(KTextEditor::Range::invalid()); | 2074 | m_bmEnd->setRange(KTextEditor::Range::invalid()); | ||
2075 | m_bmLastFlashPos->setPosition(KTextEditor::Cursor::invalid()); | 2075 | m_bmLastFlashPos->setPosition(KTextEditor::Cursor::invalid()); | ||
2076 | } | 2076 | } | ||
2077 | 2077 | | |||
2078 | bool KateViewInternal::tagLine(const KTextEditor::Cursor &virtualCursor) | 2078 | bool KateViewInternal::tagLine(const KTextEditor::Cursor &virtualCursor) | ||
2079 | { | 2079 | { | ||
2080 | // FIXME may be a more efficient way for this | 2080 | // FIXME may be a more efficient way for this | ||
2081 | if ((int)m_view->textFolding().visibleLineToLine(virtualCursor.line()) > doc()->lastLine()) { | 2081 | if ((int)view()->textFolding().visibleLineToLine(virtualCursor.line()) > doc()->lastLine()) { | ||
2082 | return false; | 2082 | return false; | ||
2083 | } | 2083 | } | ||
2084 | // End FIXME | 2084 | // End FIXME | ||
2085 | 2085 | | |||
2086 | int viewLine = cache()->displayViewLine(virtualCursor, true); | 2086 | int viewLine = cache()->displayViewLine(virtualCursor, true); | ||
2087 | if (viewLine >= 0 && viewLine < cache()->viewCacheLineCount()) { | 2087 | if (viewLine >= 0 && viewLine < cache()->viewCacheLineCount()) { | ||
2088 | cache()->viewLine(viewLine).setDirty(); | 2088 | cache()->viewLine(viewLine).setDirty(); | ||
2089 | 2089 | | |||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Line(s) | 2136 | for (int z = 0; z < cache()->viewCacheLineCount(); z++) { | |||
2138 | if ((line.virtualLine() > start.line() || (line.virtualLine() == start.line() && line.endCol() >= start.column() && start.column() != -1)) && | 2138 | if ((line.virtualLine() > start.line() || (line.virtualLine() == start.line() && line.endCol() >= start.column() && start.column() != -1)) && | ||
2139 | (line.virtualLine() < end.line() || (line.virtualLine() == end.line() && (line.startCol() <= end.column() || end.column() == -1)))) { | 2139 | (line.virtualLine() < end.line() || (line.virtualLine() == end.line() && (line.startCol() <= end.column() || end.column() == -1)))) { | ||
2140 | ret = true; | 2140 | ret = true; | ||
2141 | break; | 2141 | break; | ||
2142 | //qCDebug(LOG_KTE) << "Tagged line " << line.line(); | 2142 | //qCDebug(LOG_KTE) << "Tagged line " << line.line(); | ||
2143 | } | 2143 | } | ||
2144 | } | 2144 | } | ||
2145 | 2145 | | |||
2146 | if (!m_view->dynWordWrap()) { | 2146 | if (!view()->dynWordWrap()) { | ||
2147 | int y = lineToY(start.line()); | 2147 | int y = lineToY(start.line()); | ||
2148 | // FIXME is this enough for when multiple lines are deleted | 2148 | // FIXME is this enough for when multiple lines are deleted | ||
2149 | int h = (end.line() - start.line() + 2) * renderer()->lineHeight(); | 2149 | int h = (end.line() - start.line() + 2) * renderer()->lineHeight(); | ||
2150 | if (end.line() >= m_view->textFolding().visibleLines() - 1) { | 2150 | if (end.line() >= view()->textFolding().visibleLines() - 1) { | ||
2151 | h = height(); | 2151 | h = height(); | ||
2152 | } | 2152 | } | ||
2153 | 2153 | | |||
2154 | m_leftBorder->update(0, y, m_leftBorder->width(), h); | 2154 | m_leftBorder->update(0, y, m_leftBorder->width(), h); | ||
2155 | } else { | 2155 | } else { | ||
2156 | // FIXME Do we get enough good info in editRemoveText to optimize this more? | 2156 | // FIXME Do we get enough good info in editRemoveText to optimize this more? | ||
2157 | //bool justTagged = false; | 2157 | //bool justTagged = false; | ||
2158 | for (int z = 0; z < cache()->viewCacheLineCount(); z++) { | 2158 | for (int z = 0; z < cache()->viewCacheLineCount(); z++) { | ||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | |||||
2202 | { | 2202 | { | ||
2203 | KateTextLayout thisLine = yToKateTextLayout(p.y()); | 2203 | KateTextLayout thisLine = yToKateTextLayout(p.y()); | ||
2204 | KTextEditor::Cursor c; | 2204 | KTextEditor::Cursor c; | ||
2205 | 2205 | | |||
2206 | if (!thisLine.isValid()) { // probably user clicked below the last line -> use the last line | 2206 | if (!thisLine.isValid()) { // probably user clicked below the last line -> use the last line | ||
2207 | thisLine = cache()->textLayout(doc()->lines() - 1, -1); | 2207 | thisLine = cache()->textLayout(doc()->lines() - 1, -1); | ||
2208 | } | 2208 | } | ||
2209 | 2209 | | |||
2210 | c = renderer()->xToCursor(thisLine, startX() + p.x(), !m_view->wrapCursor()); | 2210 | c = renderer()->xToCursor(thisLine, startX() + p.x(), !view()->wrapCursor()); | ||
2211 | 2211 | | |||
2212 | if (c.line() < 0 || c.line() >= doc()->lines()) { | 2212 | if (c.line() < 0 || c.line() >= doc()->lines()) { | ||
2213 | return; | 2213 | return; | ||
2214 | } | 2214 | } | ||
2215 | 2215 | | |||
2216 | if (updateSelection) { | 2216 | if (updateSelection) { | ||
2217 | KateViewInternal::updateSelection(c, keepSelection); | 2217 | KateViewInternal::updateSelection(c, keepSelection); | ||
2218 | } | 2218 | } | ||
Show All 11 Lines | |||||
2230 | // Point in content coordinates | 2230 | // Point in content coordinates | ||
2231 | bool KateViewInternal::isTargetSelected(const QPoint &p) | 2231 | bool KateViewInternal::isTargetSelected(const QPoint &p) | ||
2232 | { | 2232 | { | ||
2233 | const KateTextLayout &thisLine = yToKateTextLayout(p.y()); | 2233 | const KateTextLayout &thisLine = yToKateTextLayout(p.y()); | ||
2234 | if (!thisLine.isValid()) { | 2234 | if (!thisLine.isValid()) { | ||
2235 | return false; | 2235 | return false; | ||
2236 | } | 2236 | } | ||
2237 | 2237 | | |||
2238 | return m_view->cursorSelected(renderer()->xToCursor(thisLine, startX() + p.x(), !m_view->wrapCursor())); | 2238 | return view()->cursorSelected(renderer()->xToCursor(thisLine, startX() + p.x(), !view()->wrapCursor())); | ||
2239 | } | 2239 | } | ||
2240 | 2240 | | |||
2241 | //BEGIN EVENT HANDLING STUFF | 2241 | //BEGIN EVENT HANDLING STUFF | ||
2242 | 2242 | | |||
2243 | bool KateViewInternal::eventFilter(QObject *obj, QEvent *e) | 2243 | bool KateViewInternal::eventFilter(QObject *obj, QEvent *e) | ||
2244 | { | 2244 | { | ||
2245 | 2245 | | |||
2246 | switch (e->type()) { | 2246 | switch (e->type()) { | ||
Show All 12 Lines | 2258 | /*foreach (QWidget* child, c->child()->findChildren<QWidget*>()) | |||
2259 | child->removeEventFilter(this);*/ | 2259 | child->removeEventFilter(this);*/ | ||
2260 | } | 2260 | } | ||
2261 | } break; | 2261 | } break; | ||
2262 | 2262 | | |||
2263 | case QEvent::ShortcutOverride: { | 2263 | case QEvent::ShortcutOverride: { | ||
2264 | QKeyEvent *k = static_cast<QKeyEvent *>(e); | 2264 | QKeyEvent *k = static_cast<QKeyEvent *>(e); | ||
2265 | 2265 | | |||
2266 | if (k->key() == Qt::Key_Escape && k->modifiers() == Qt::NoModifier) { | 2266 | if (k->key() == Qt::Key_Escape && k->modifiers() == Qt::NoModifier) { | ||
2267 | if (m_view->isCompletionActive()) { | 2267 | if (view()->isCompletionActive()) { | ||
2268 | m_view->abortCompletion(); | 2268 | view()->abortCompletion(); | ||
2269 | k->accept(); | 2269 | k->accept(); | ||
2270 | //qCDebug(LOG_KTE) << obj << "shortcut override" << k->key() << "aborting completion"; | 2270 | //qCDebug(LOG_KTE) << obj << "shortcut override" << k->key() << "aborting completion"; | ||
2271 | return true; | 2271 | return true; | ||
2272 | } else if (!m_view->bottomViewBar()->hiddenOrPermanent()) { | 2272 | } else if (!view()->bottomViewBar()->hiddenOrPermanent()) { | ||
2273 | m_view->bottomViewBar()->hideCurrentBarWidget(); | 2273 | view()->bottomViewBar()->hideCurrentBarWidget(); | ||
2274 | k->accept(); | 2274 | k->accept(); | ||
2275 | //qCDebug(LOG_KTE) << obj << "shortcut override" << k->key() << "closing view bar"; | 2275 | //qCDebug(LOG_KTE) << obj << "shortcut override" << k->key() << "closing view bar"; | ||
2276 | return true; | 2276 | return true; | ||
2277 | } else if (!m_view->config()->persistentSelection() && m_view->selection()) { | 2277 | } else if (!view()->config()->persistentSelection() && view()->selection()) { | ||
2278 | m_currentInputMode->clearSelection(); | 2278 | m_currentInputMode->clearSelection(); | ||
2279 | k->accept(); | 2279 | k->accept(); | ||
2280 | //qCDebug(LOG_KTE) << obj << "shortcut override" << k->key() << "clearing selection"; | 2280 | //qCDebug(LOG_KTE) << obj << "shortcut override" << k->key() << "clearing selection"; | ||
2281 | return true; | 2281 | return true; | ||
2282 | } | 2282 | } | ||
2283 | } | 2283 | } | ||
2284 | 2284 | | |||
2285 | if (m_currentInputMode->stealKey(k)) { | 2285 | if (m_currentInputMode->stealKey(k)) { | ||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Line(s) | |||||
2330 | } | 2330 | } | ||
2331 | 2331 | | |||
2332 | return QWidget::eventFilter(obj, e); | 2332 | return QWidget::eventFilter(obj, e); | ||
2333 | } | 2333 | } | ||
2334 | 2334 | | |||
2335 | void KateViewInternal::keyPressEvent(QKeyEvent *e) | 2335 | void KateViewInternal::keyPressEvent(QKeyEvent *e) | ||
2336 | { | 2336 | { | ||
2337 | if (e->key() == Qt::Key_Left && e->modifiers() == Qt::AltModifier) { | 2337 | if (e->key() == Qt::Key_Left && e->modifiers() == Qt::AltModifier) { | ||
2338 | m_view->emitNavigateLeft(); | 2338 | view()->emitNavigateLeft(); | ||
2339 | e->setAccepted(true); | 2339 | e->setAccepted(true); | ||
2340 | return; | 2340 | return; | ||
2341 | } | 2341 | } | ||
2342 | if (e->key() == Qt::Key_Right && e->modifiers() == Qt::AltModifier) { | 2342 | if (e->key() == Qt::Key_Right && e->modifiers() == Qt::AltModifier) { | ||
2343 | m_view->emitNavigateRight(); | 2343 | view()->emitNavigateRight(); | ||
2344 | e->setAccepted(true); | 2344 | e->setAccepted(true); | ||
2345 | return; | 2345 | return; | ||
2346 | } | 2346 | } | ||
2347 | if (e->key() == Qt::Key_Up && e->modifiers() == Qt::AltModifier) { | 2347 | if (e->key() == Qt::Key_Up && e->modifiers() == Qt::AltModifier) { | ||
2348 | m_view->emitNavigateUp(); | 2348 | view()->emitNavigateUp(); | ||
2349 | e->setAccepted(true); | 2349 | e->setAccepted(true); | ||
2350 | return; | 2350 | return; | ||
2351 | } | 2351 | } | ||
2352 | if (e->key() == Qt::Key_Down && e->modifiers() == Qt::AltModifier) { | 2352 | if (e->key() == Qt::Key_Down && e->modifiers() == Qt::AltModifier) { | ||
2353 | m_view->emitNavigateDown(); | 2353 | view()->emitNavigateDown(); | ||
2354 | e->setAccepted(true); | 2354 | e->setAccepted(true); | ||
2355 | return; | 2355 | return; | ||
2356 | } | 2356 | } | ||
2357 | if (e->key() == Qt::Key_Return && e->modifiers() == Qt::AltModifier) { | 2357 | if (e->key() == Qt::Key_Return && e->modifiers() == Qt::AltModifier) { | ||
2358 | m_view->emitNavigateAccept(); | 2358 | view()->emitNavigateAccept(); | ||
2359 | e->setAccepted(true); | 2359 | e->setAccepted(true); | ||
2360 | return; | 2360 | return; | ||
2361 | } | 2361 | } | ||
2362 | if (e->key() == Qt::Key_Backspace && e->modifiers() == Qt::AltModifier) { | 2362 | if (e->key() == Qt::Key_Backspace && e->modifiers() == Qt::AltModifier) { | ||
2363 | m_view->emitNavigateBack(); | 2363 | view()->emitNavigateBack(); | ||
2364 | e->setAccepted(true); | 2364 | e->setAccepted(true); | ||
2365 | return; | 2365 | return; | ||
2366 | } | 2366 | } | ||
2367 | 2367 | | |||
2368 | if (e->key() == Qt::Key_Alt && m_view->completionWidget()->isCompletionActive()) { | 2368 | if (e->key() == Qt::Key_Alt && view()->completionWidget()->isCompletionActive()) { | ||
2369 | m_completionItemExpanded = m_view->completionWidget()->toggleExpanded(true); | 2369 | m_completionItemExpanded = view()->completionWidget()->toggleExpanded(true); | ||
2370 | m_view->completionWidget()->resetHadNavigation(); | 2370 | view()->completionWidget()->resetHadNavigation(); | ||
2371 | m_altDownTime.start(); | 2371 | m_altDownTime.start(); | ||
2372 | } | 2372 | } | ||
2373 | 2373 | | |||
2374 | // Note: AND'ing with <Shift> is a quick hack to fix Key_Enter | 2374 | // Note: AND'ing with <Shift> is a quick hack to fix Key_Enter | ||
2375 | const int key = e->key() | (e->modifiers() & Qt::ShiftModifier); | 2375 | const int key = e->key() | (e->modifiers() & Qt::ShiftModifier); | ||
2376 | 2376 | | |||
2377 | if (m_currentInputMode->keyPress(e)) { | 2377 | if (m_currentInputMode->keyPress(e)) { | ||
2378 | return; | 2378 | return; | ||
2379 | } | 2379 | } | ||
2380 | 2380 | | |||
2381 | 2381 | | |||
2382 | if (!doc()->isReadWrite()) { | 2382 | if (!doc()->isReadWrite()) { | ||
2383 | e->ignore(); | 2383 | e->ignore(); | ||
2384 | return; | 2384 | return; | ||
2385 | } | 2385 | } | ||
2386 | 2386 | | |||
2387 | if ((key == Qt::Key_Return) || (key == Qt::Key_Enter) || (key == Qt::SHIFT + Qt::Key_Return) || (key == Qt::SHIFT + Qt::Key_Enter)) { | 2387 | if ((key == Qt::Key_Return) || (key == Qt::Key_Enter) || (key == Qt::SHIFT + Qt::Key_Return) || (key == Qt::SHIFT + Qt::Key_Enter)) { | ||
2388 | m_view->keyReturn(); | 2388 | view()->keyReturn(); | ||
2389 | e->accept(); | 2389 | e->accept(); | ||
2390 | return; | 2390 | return; | ||
2391 | } | 2391 | } | ||
2392 | 2392 | | |||
2393 | if (key == Qt::Key_Backspace || key == Qt::SHIFT + Qt::Key_Backspace) { | 2393 | if (key == Qt::Key_Backspace || key == Qt::SHIFT + Qt::Key_Backspace) { | ||
2394 | //m_view->backspace(); | 2394 | //view()->backspace(); | ||
2395 | e->accept(); | 2395 | e->accept(); | ||
2396 | 2396 | | |||
2397 | return; | 2397 | return; | ||
2398 | } | 2398 | } | ||
2399 | 2399 | | |||
2400 | if (key == Qt::Key_Tab || key == Qt::SHIFT + Qt::Key_Backtab || key == Qt::Key_Backtab) { | 2400 | if (key == Qt::Key_Tab || key == Qt::SHIFT + Qt::Key_Backtab || key == Qt::Key_Backtab) { | ||
2401 | if (m_view->completionWidget()->isCompletionActive()) { | 2401 | if (view()->completionWidget()->isCompletionActive()) { | ||
2402 | e->accept(); | 2402 | e->accept(); | ||
2403 | m_view->completionWidget()->tab(key != Qt::Key_Tab); | 2403 | view()->completionWidget()->tab(key != Qt::Key_Tab); | ||
2404 | return; | 2404 | return; | ||
2405 | } | 2405 | } | ||
2406 | 2406 | | |||
2407 | if (key == Qt::Key_Tab) { | 2407 | if (key == Qt::Key_Tab) { | ||
2408 | uint tabHandling = doc()->config()->tabHandling(); | 2408 | uint tabHandling = doc()->config()->tabHandling(); | ||
2409 | // convert tabSmart into tabInsertsTab or tabIndents: | 2409 | // convert tabSmart into tabInsertsTab or tabIndents: | ||
2410 | if (tabHandling == KateDocumentConfig::tabSmart) { | 2410 | if (tabHandling == KateDocumentConfig::tabSmart) { | ||
2411 | // multiple lines selected | 2411 | // multiple lines selected | ||
2412 | if (m_view->selection() && !m_view->selectionRange().onSingleLine()) { | 2412 | if (view()->selection() && !view()->selectionRange().onSingleLine()) { | ||
2413 | tabHandling = KateDocumentConfig::tabIndents; | 2413 | tabHandling = KateDocumentConfig::tabIndents; | ||
2414 | } | 2414 | } | ||
2415 | 2415 | | |||
2416 | // otherwise: take look at cursor position | 2416 | // otherwise: take look at cursor position | ||
2417 | else { | 2417 | else { | ||
2418 | // if the cursor is at or before the first non-space character | 2418 | // if the cursor is at or before the first non-space character | ||
2419 | // or on an empty line, | 2419 | // or on an empty line, | ||
2420 | // Tab indents, otherwise it inserts a tab character. | 2420 | // Tab indents, otherwise it inserts a tab character. | ||
2421 | Kate::TextLine line = doc()->kateTextLine(m_cursor.line()); | 2421 | Kate::TextLine line = doc()->kateTextLine(m_cursor.line()); | ||
2422 | int first = line->firstChar(); | 2422 | int first = line->firstChar(); | ||
2423 | if (first < 0 || m_cursor.column() <= first) { | 2423 | if (first < 0 || m_cursor.column() <= first) { | ||
2424 | tabHandling = KateDocumentConfig::tabIndents; | 2424 | tabHandling = KateDocumentConfig::tabIndents; | ||
2425 | } else { | 2425 | } else { | ||
2426 | tabHandling = KateDocumentConfig::tabInsertsTab; | 2426 | tabHandling = KateDocumentConfig::tabInsertsTab; | ||
2427 | } | 2427 | } | ||
2428 | } | 2428 | } | ||
2429 | } | 2429 | } | ||
2430 | 2430 | | |||
2431 | if (tabHandling == KateDocumentConfig::tabInsertsTab) { | 2431 | if (tabHandling == KateDocumentConfig::tabInsertsTab) { | ||
2432 | doc()->typeChars(m_view, QStringLiteral("\t")); | 2432 | doc()->typeChars(m_view, QStringLiteral("\t")); | ||
2433 | } else { | 2433 | } else { | ||
2434 | doc()->indent(m_view->selection() ? m_view->selectionRange() : KTextEditor::Range(m_cursor.line(), 0, m_cursor.line(), 0), 1); | 2434 | doc()->indent(view()->selection() ? view()->selectionRange() : KTextEditor::Range(m_cursor.line(), 0, m_cursor.line(), 0), 1); | ||
2435 | } | 2435 | } | ||
2436 | 2436 | | |||
2437 | e->accept(); | 2437 | e->accept(); | ||
2438 | 2438 | | |||
2439 | return; | 2439 | return; | ||
2440 | } else if (doc()->config()->tabHandling() != KateDocumentConfig::tabInsertsTab) { | 2440 | } else if (doc()->config()->tabHandling() != KateDocumentConfig::tabInsertsTab) { | ||
2441 | // key == Qt::SHIFT+Qt::Key_Backtab || key == Qt::Key_Backtab | 2441 | // key == Qt::SHIFT+Qt::Key_Backtab || key == Qt::Key_Backtab | ||
2442 | doc()->indent(m_view->selection() ? m_view->selectionRange() : KTextEditor::Range(m_cursor.line(), 0, m_cursor.line(), 0), -1); | 2442 | doc()->indent(view()->selection() ? view()->selectionRange() : KTextEditor::Range(m_cursor.line(), 0, m_cursor.line(), 0), -1); | ||
2443 | e->accept(); | 2443 | e->accept(); | ||
2444 | 2444 | | |||
2445 | return; | 2445 | return; | ||
2446 | } | 2446 | } | ||
2447 | } | 2447 | } | ||
2448 | 2448 | | |||
2449 | if (!(e->modifiers() & Qt::ControlModifier) && !e->text().isEmpty() && doc()->typeChars(m_view, e->text())) { | 2449 | if (!(e->modifiers() & Qt::ControlModifier) && !e->text().isEmpty() && doc()->typeChars(m_view, e->text())) { | ||
2450 | e->accept(); | 2450 | e->accept(); | ||
Show All 9 Lines | 2457 | if ((e->modifiers() & altGR) == altGR && !e->text().isEmpty() && doc()->typeChars(m_view, e->text())) { | |||
2460 | return; | 2460 | return; | ||
2461 | } | 2461 | } | ||
2462 | 2462 | | |||
2463 | e->ignore(); | 2463 | e->ignore(); | ||
2464 | } | 2464 | } | ||
2465 | 2465 | | |||
2466 | void KateViewInternal::keyReleaseEvent(QKeyEvent *e) | 2466 | void KateViewInternal::keyReleaseEvent(QKeyEvent *e) | ||
2467 | { | 2467 | { | ||
2468 | if (e->key() == Qt::Key_Alt && m_view->completionWidget()->isCompletionActive() && ((m_completionItemExpanded && (m_view->completionWidget()->hadNavigation() || m_altDownTime.elapsed() > 300)) || (!m_completionItemExpanded && !m_view->completionWidget()->hadNavigation()))) { | 2468 | if (e->key() == Qt::Key_Alt && view()->completionWidget()->isCompletionActive() && ((m_completionItemExpanded && (view()->completionWidget()->hadNavigation() || m_altDownTime.elapsed() > 300)) || (!m_completionItemExpanded && !view()->completionWidget()->hadNavigation()))) { | ||
2469 | 2469 | | |||
2470 | m_view->completionWidget()->toggleExpanded(false, true); | 2470 | view()->completionWidget()->toggleExpanded(false, true); | ||
2471 | } | 2471 | } | ||
2472 | 2472 | | |||
2473 | if ((e->modifiers() & Qt::SHIFT) == Qt::SHIFT) { | 2473 | if ((e->modifiers() & Qt::SHIFT) == Qt::SHIFT) { | ||
2474 | m_shiftKeyPressed = true; | 2474 | m_shiftKeyPressed = true; | ||
2475 | } else { | 2475 | } else { | ||
2476 | if (m_shiftKeyPressed) { | 2476 | if (m_shiftKeyPressed) { | ||
2477 | m_shiftKeyPressed = false; | 2477 | m_shiftKeyPressed = false; | ||
2478 | 2478 | | |||
2479 | if (m_selChangedByUser) { | 2479 | if (m_selChangedByUser) { | ||
2480 | if (m_view->selection()) { | 2480 | if (view()->selection()) { | ||
2481 | QApplication::clipboard()->setText(m_view->selectionText(), QClipboard::Selection); | 2481 | QApplication::clipboard()->setText(view()->selectionText(), QClipboard::Selection); | ||
2482 | } | 2482 | } | ||
2483 | 2483 | | |||
2484 | m_selChangedByUser = false; | 2484 | m_selChangedByUser = false; | ||
2485 | } | 2485 | } | ||
2486 | } | 2486 | } | ||
2487 | } | 2487 | } | ||
2488 | 2488 | | |||
2489 | e->ignore(); | 2489 | e->ignore(); | ||
2490 | return; | 2490 | return; | ||
2491 | } | 2491 | } | ||
2492 | 2492 | | |||
2493 | void KateViewInternal::contextMenuEvent(QContextMenuEvent *e) | 2493 | void KateViewInternal::contextMenuEvent(QContextMenuEvent *e) | ||
2494 | { | 2494 | { | ||
2495 | // try to show popup menu | 2495 | // try to show popup menu | ||
2496 | 2496 | | |||
2497 | QPoint p = e->pos(); | 2497 | QPoint p = e->pos(); | ||
2498 | 2498 | | |||
2499 | if (e->reason() == QContextMenuEvent::Keyboard) { | 2499 | if (e->reason() == QContextMenuEvent::Keyboard) { | ||
2500 | makeVisible(m_displayCursor, 0); | 2500 | makeVisible(m_displayCursor, 0); | ||
2501 | p = cursorCoordinates(false); | 2501 | p = cursorCoordinates(false); | ||
2502 | p.rx() -= startX(); | 2502 | p.rx() -= startX(); | ||
2503 | } else if (! m_view->selection() || m_view->config()->persistentSelection()) { | 2503 | } else if (! view()->selection() || view()->config()->persistentSelection()) { | ||
2504 | placeCursor(e->pos()); | 2504 | placeCursor(e->pos()); | ||
2505 | } | 2505 | } | ||
2506 | 2506 | | |||
2507 | // popup is a qguardedptr now | 2507 | // popup is a qguardedptr now | ||
2508 | if (m_view->contextMenu()) { | 2508 | if (view()->contextMenu()) { | ||
2509 | m_view->spellingMenu()->setUseMouseForMisspelledRange((e->reason() == QContextMenuEvent::Mouse)); | 2509 | view()->spellingMenu()->setUseMouseForMisspelledRange((e->reason() == QContextMenuEvent::Mouse)); | ||
2510 | m_view->contextMenu()->popup(mapToGlobal(p)); | 2510 | view()->contextMenu()->popup(mapToGlobal(p)); | ||
2511 | e->accept(); | 2511 | e->accept(); | ||
2512 | } | 2512 | } | ||
2513 | } | 2513 | } | ||
2514 | 2514 | | |||
2515 | void KateViewInternal::mousePressEvent(QMouseEvent *e) | 2515 | void KateViewInternal::mousePressEvent(QMouseEvent *e) | ||
2516 | { | 2516 | { | ||
2517 | // was an inline note clicked? | 2517 | // was an inline note clicked? | ||
2518 | const auto noteData = inlineNoteAt(e->globalPos()); | 2518 | const auto noteData = inlineNoteAt(e->globalPos()); | ||
Show All 12 Lines | 2527 | case Qt::LeftButton: | |||
2531 | if (m_possibleTripleClick) { | 2531 | if (m_possibleTripleClick) { | ||
2532 | m_possibleTripleClick = false; | 2532 | m_possibleTripleClick = false; | ||
2533 | 2533 | | |||
2534 | m_selectionMode = Line; | 2534 | m_selectionMode = Line; | ||
2535 | 2535 | | |||
2536 | if (e->modifiers() & Qt::ShiftModifier) { | 2536 | if (e->modifiers() & Qt::ShiftModifier) { | ||
2537 | updateSelection(m_cursor, true); | 2537 | updateSelection(m_cursor, true); | ||
2538 | } else { | 2538 | } else { | ||
2539 | m_view->selectLine(m_cursor); | 2539 | view()->selectLine(m_cursor); | ||
2540 | if (m_view->selection()) { | 2540 | if (view()->selection()) { | ||
2541 | m_selectAnchor = m_view->selectionRange().start(); | 2541 | m_selectAnchor = view()->selectionRange().start(); | ||
2542 | } | 2542 | } | ||
2543 | } | 2543 | } | ||
2544 | 2544 | | |||
2545 | if (m_view->selection()) { | 2545 | if (view()->selection()) { | ||
2546 | QApplication::clipboard()->setText(m_view->selectionText(), QClipboard::Selection); | 2546 | QApplication::clipboard()->setText(view()->selectionText(), QClipboard::Selection); | ||
2547 | } | 2547 | } | ||
2548 | 2548 | | |||
2549 | // Keep the line at the select anchor selected during further | 2549 | // Keep the line at the select anchor selected during further | ||
2550 | // mouse selection | 2550 | // mouse selection | ||
2551 | if (m_selectAnchor.line() > m_view->selectionRange().start().line()) { | 2551 | if (m_selectAnchor.line() > view()->selectionRange().start().line()) { | ||
2552 | // Preserve the last selected line | 2552 | // Preserve the last selected line | ||
2553 | if (m_selectAnchor == m_view->selectionRange().end() && m_selectAnchor.column() == 0) { | 2553 | if (m_selectAnchor == view()->selectionRange().end() && m_selectAnchor.column() == 0) { | ||
2554 | m_selectionCached.setStart(KTextEditor::Cursor(m_selectAnchor.line() - 1, 0)); | 2554 | m_selectionCached.setStart(KTextEditor::Cursor(m_selectAnchor.line() - 1, 0)); | ||
2555 | } else { | 2555 | } else { | ||
2556 | m_selectionCached.setStart(KTextEditor::Cursor(m_selectAnchor.line(), 0)); | 2556 | m_selectionCached.setStart(KTextEditor::Cursor(m_selectAnchor.line(), 0)); | ||
2557 | } | 2557 | } | ||
2558 | m_selectionCached.setEnd(m_view->selectionRange().end()); | 2558 | m_selectionCached.setEnd(view()->selectionRange().end()); | ||
2559 | } else { | 2559 | } else { | ||
2560 | // Preserve the first selected line | 2560 | // Preserve the first selected line | ||
2561 | m_selectionCached.setStart(m_view->selectionRange().start()); | 2561 | m_selectionCached.setStart(view()->selectionRange().start()); | ||
2562 | if (m_view->selectionRange().end().line() > m_view->selectionRange().start().line()) { | 2562 | if (view()->selectionRange().end().line() > view()->selectionRange().start().line()) { | ||
2563 | m_selectionCached.setEnd(KTextEditor::Cursor(m_view->selectionRange().start().line() + 1, 0)); | 2563 | m_selectionCached.setEnd(KTextEditor::Cursor(view()->selectionRange().start().line() + 1, 0)); | ||
2564 | } else { | 2564 | } else { | ||
2565 | m_selectionCached.setEnd(m_view->selectionRange().end()); | 2565 | m_selectionCached.setEnd(view()->selectionRange().end()); | ||
2566 | } | 2566 | } | ||
2567 | } | 2567 | } | ||
2568 | 2568 | | |||
2569 | moveCursorToSelectionEdge(); | 2569 | moveCursorToSelectionEdge(); | ||
2570 | 2570 | | |||
2571 | m_scrollX = 0; | 2571 | m_scrollX = 0; | ||
2572 | m_scrollY = 0; | 2572 | m_scrollY = 0; | ||
2573 | m_scrollTimer.start(50); | 2573 | m_scrollTimer.start(50); | ||
▲ Show 20 Lines • Show All 95 Lines • ▼ Show 20 Line(s) | 2639 | if (e->modifiers() & Qt::ShiftModifier) { | |||
2669 | // Now word select to the mouse cursor | 2669 | // Now word select to the mouse cursor | ||
2670 | placeCursor(e->pos(), true); | 2670 | placeCursor(e->pos(), true); | ||
2671 | } else { | 2671 | } else { | ||
2672 | // first clear the selection, otherwise we run into bug #106402 | 2672 | // first clear the selection, otherwise we run into bug #106402 | ||
2673 | // ...and set the cursor position, for the same reason (otherwise there | 2673 | // ...and set the cursor position, for the same reason (otherwise there | ||
2674 | // are *other* idiosyncrasies we can't fix without reintroducing said | 2674 | // are *other* idiosyncrasies we can't fix without reintroducing said | ||
2675 | // bug) | 2675 | // bug) | ||
2676 | // Parameters: don't redraw, and don't emit selectionChanged signal yet | 2676 | // Parameters: don't redraw, and don't emit selectionChanged signal yet | ||
2677 | m_view->clearSelection(false, false); | 2677 | view()->clearSelection(false, false); | ||
2678 | placeCursor(e->pos()); | 2678 | placeCursor(e->pos()); | ||
2679 | m_view->selectWord(m_cursor); | 2679 | view()->selectWord(m_cursor); | ||
2680 | cursorToMatchingBracket(true); | 2680 | cursorToMatchingBracket(true); | ||
2681 | 2681 | | |||
2682 | if (m_view->selection()) { | 2682 | if (view()->selection()) { | ||
2683 | m_selectAnchor = m_view->selectionRange().start(); | 2683 | m_selectAnchor = view()->selectionRange().start(); | ||
2684 | m_selectionCached = m_view->selectionRange(); | 2684 | m_selectionCached = view()->selectionRange(); | ||
2685 | } else { | 2685 | } else { | ||
2686 | m_selectAnchor = m_cursor; | 2686 | m_selectAnchor = m_cursor; | ||
2687 | m_selectionCached = KTextEditor::Range(m_cursor, m_cursor); | 2687 | m_selectionCached = KTextEditor::Range(m_cursor, m_cursor); | ||
2688 | } | 2688 | } | ||
2689 | } | 2689 | } | ||
2690 | 2690 | | |||
2691 | // Move cursor to end (or beginning) of selected word | 2691 | // Move cursor to end (or beginning) of selected word | ||
2692 | if (m_view->selection()) { | 2692 | if (view()->selection()) { | ||
2693 | #if !defined(Q_OS_OSX) | 2693 | #if !defined(Q_OS_OSX) | ||
2694 | QApplication::clipboard()->setText(m_view->selectionText(), QClipboard::Selection); | 2694 | QApplication::clipboard()->setText(view()->selectionText(), QClipboard::Selection); | ||
2695 | #endif | 2695 | #endif | ||
2696 | } | 2696 | } | ||
2697 | 2697 | | |||
2698 | moveCursorToSelectionEdge(); | 2698 | moveCursorToSelectionEdge(); | ||
2699 | m_possibleTripleClick = true; | 2699 | m_possibleTripleClick = true; | ||
2700 | QTimer::singleShot(QApplication::doubleClickInterval(), this, SLOT(tripleClickTimeout())); | 2700 | QTimer::singleShot(QApplication::doubleClickInterval(), this, SLOT(tripleClickTimeout())); | ||
2701 | 2701 | | |||
2702 | m_scrollX = 0; | 2702 | m_scrollX = 0; | ||
Show All 24 Lines | |||||
2727 | void KateViewInternal::mouseReleaseEvent(QMouseEvent *e) | 2727 | void KateViewInternal::mouseReleaseEvent(QMouseEvent *e) | ||
2728 | { | 2728 | { | ||
2729 | switch (e->button()) { | 2729 | switch (e->button()) { | ||
2730 | case Qt::LeftButton: | 2730 | case Qt::LeftButton: | ||
2731 | m_selectionMode = Default; | 2731 | m_selectionMode = Default; | ||
2732 | // m_selectionCached.start().setLine( -1 ); | 2732 | // m_selectionCached.start().setLine( -1 ); | ||
2733 | 2733 | | |||
2734 | if (m_selChangedByUser) { | 2734 | if (m_selChangedByUser) { | ||
2735 | if (m_view->selection()) { | 2735 | if (view()->selection()) { | ||
2736 | QApplication::clipboard()->setText(m_view->selectionText(), QClipboard::Selection); | 2736 | QApplication::clipboard()->setText(view()->selectionText(), QClipboard::Selection); | ||
2737 | } | 2737 | } | ||
2738 | moveCursorToSelectionEdge(); | 2738 | moveCursorToSelectionEdge(); | ||
2739 | 2739 | | |||
2740 | m_selChangedByUser = false; | 2740 | m_selChangedByUser = false; | ||
2741 | } | 2741 | } | ||
2742 | 2742 | | |||
2743 | if (m_dragInfo.state == diPending) { | 2743 | if (m_dragInfo.state == diPending) { | ||
2744 | placeCursor(e->pos(), e->modifiers() & Qt::ShiftModifier); | 2744 | placeCursor(e->pos(), e->modifiers() & Qt::ShiftModifier); | ||
2745 | } else if (m_dragInfo.state == diNone) { | 2745 | } else if (m_dragInfo.state == diNone) { | ||
2746 | m_scrollTimer.stop(); | 2746 | m_scrollTimer.stop(); | ||
2747 | } | 2747 | } | ||
2748 | 2748 | | |||
2749 | m_dragInfo.state = diNone; | 2749 | m_dragInfo.state = diNone; | ||
2750 | 2750 | | |||
2751 | e->accept(); | 2751 | e->accept(); | ||
2752 | break; | 2752 | break; | ||
2753 | 2753 | | |||
2754 | case Qt::MidButton: | 2754 | case Qt::MidButton: | ||
2755 | placeCursor(e->pos()); | 2755 | placeCursor(e->pos()); | ||
2756 | 2756 | | |||
2757 | if (doc()->isReadWrite()) { | 2757 | if (doc()->isReadWrite()) { | ||
2758 | QString clipboard = QApplication::clipboard()->text(QClipboard::Selection); | 2758 | QString clipboard = QApplication::clipboard()->text(QClipboard::Selection); | ||
2759 | m_view->paste(&clipboard); | 2759 | view()->paste(&clipboard); | ||
2760 | } | 2760 | } | ||
2761 | 2761 | | |||
2762 | e->accept(); | 2762 | e->accept(); | ||
2763 | break; | 2763 | break; | ||
2764 | 2764 | | |||
2765 | default: | 2765 | default: | ||
2766 | e->ignore(); | 2766 | e->ignore(); | ||
2767 | break; | 2767 | break; | ||
Show All 19 Lines | 2783 | { | |||
2787 | 2787 | | |||
2788 | if (includeBorder) { | 2788 | if (includeBorder) { | ||
2789 | coord.rx() -= m_leftBorder->width(); | 2789 | coord.rx() -= m_leftBorder->width(); | ||
2790 | } | 2790 | } | ||
2791 | coord.rx() += startX(); | 2791 | coord.rx() += startX(); | ||
2792 | 2792 | | |||
2793 | const KateTextLayout &thisLine = yToKateTextLayout(coord.y()); | 2793 | const KateTextLayout &thisLine = yToKateTextLayout(coord.y()); | ||
2794 | if (thisLine.isValid()) { | 2794 | if (thisLine.isValid()) { | ||
2795 | ret = renderer()->xToCursor(thisLine, coord.x(), !m_view->wrapCursor()); | 2795 | ret = renderer()->xToCursor(thisLine, coord.x(), !view()->wrapCursor()); | ||
2796 | } | 2796 | } | ||
2797 | 2797 | | |||
2798 | if (ret.column() > view()->document()->lineLength(ret.line())) { | 2798 | if (ret.column() > view()->document()->lineLength(ret.line())) { | ||
2799 | // The cursor is beyond the end of the line; in that case the renderer | 2799 | // The cursor is beyond the end of the line; in that case the renderer | ||
2800 | // gives the index of the character behind the last one. | 2800 | // gives the index of the character behind the last one. | ||
2801 | return KTextEditor::Cursor::invalid(); | 2801 | return KTextEditor::Cursor::invalid(); | ||
2802 | } | 2802 | } | ||
2803 | 2803 | | |||
▲ Show 20 Lines • Show All 140 Lines • ▼ Show 20 Line(s) | 2941 | if (!updateRegion.isEmpty()) { | |||
2944 | } | 2944 | } | ||
2945 | update(updateRegion); | 2945 | update(updateRegion); | ||
2946 | } | 2946 | } | ||
2947 | } | 2947 | } | ||
2948 | 2948 | | |||
2949 | void KateViewInternal::hideEvent(QHideEvent *e) | 2949 | void KateViewInternal::hideEvent(QHideEvent *e) | ||
2950 | { | 2950 | { | ||
2951 | Q_UNUSED(e); | 2951 | Q_UNUSED(e); | ||
2952 | if (m_view->isCompletionActive()) { | 2952 | if (view()->isCompletionActive()) { | ||
2953 | m_view->completionWidget()->abortCompletion(); | 2953 | view()->completionWidget()->abortCompletion(); | ||
2954 | } | 2954 | } | ||
2955 | } | 2955 | } | ||
2956 | 2956 | | |||
2957 | void KateViewInternal::paintEvent(QPaintEvent *e) | 2957 | void KateViewInternal::paintEvent(QPaintEvent *e) | ||
2958 | { | 2958 | { | ||
2959 | if (debugPainting) { | 2959 | if (debugPainting) { | ||
2960 | qCDebug(LOG_KTE) << "GOT PAINT EVENT: Region" << e->region(); | 2960 | qCDebug(LOG_KTE) << "GOT PAINT EVENT: Region" << e->region(); | ||
2961 | } | 2961 | } | ||
▲ Show 20 Lines • Show All 99 Lines • ▼ Show 20 Line(s) | 3056 | { | |||
3061 | m_dummy->setFixedSize(m_lineScroll->width(), m_columnScroll->sizeHint().height()); | 3061 | m_dummy->setFixedSize(m_lineScroll->width(), m_columnScroll->sizeHint().height()); | ||
3062 | m_madeVisible = false; | 3062 | m_madeVisible = false; | ||
3063 | 3063 | | |||
3064 | if (heightChanged) { | 3064 | if (heightChanged) { | ||
3065 | setAutoCenterLines(m_autoCenterLines, false); | 3065 | setAutoCenterLines(m_autoCenterLines, false); | ||
3066 | m_cachedMaxStartPos.setPosition(-1, -1); | 3066 | m_cachedMaxStartPos.setPosition(-1, -1); | ||
3067 | } | 3067 | } | ||
3068 | 3068 | | |||
3069 | if (m_view->dynWordWrap()) { | 3069 | if (view()->dynWordWrap()) { | ||
3070 | bool dirtied = false; | 3070 | bool dirtied = false; | ||
3071 | 3071 | | |||
3072 | for (int i = 0; i < cache()->viewCacheLineCount(); i++) { | 3072 | for (int i = 0; i < cache()->viewCacheLineCount(); i++) { | ||
3073 | // find the first dirty line | 3073 | // find the first dirty line | ||
3074 | // the word wrap updateView algorithm is forced to check all lines after a dirty one | 3074 | // the word wrap updateView algorithm is forced to check all lines after a dirty one | ||
3075 | KateTextLayout viewLine = cache()->viewLine(i); | 3075 | KateTextLayout viewLine = cache()->viewLine(i); | ||
3076 | 3076 | | |||
3077 | if (viewLine.wrap() || viewLine.isRightToLeft() || viewLine.width() > width()) { | 3077 | if (viewLine.wrap() || viewLine.isRightToLeft() || viewLine.width() > width()) { | ||
Show All 10 Lines | |||||
3088 | } else { | 3088 | } else { | ||
3089 | updateView(); | 3089 | updateView(); | ||
3090 | 3090 | | |||
3091 | if (expandedHorizontally && startX() > 0) { | 3091 | if (expandedHorizontally && startX() > 0) { | ||
3092 | scrollColumns(startX() - (width() - e->oldSize().width())); | 3092 | scrollColumns(startX() - (width() - e->oldSize().width())); | ||
3093 | } | 3093 | } | ||
3094 | } | 3094 | } | ||
3095 | 3095 | | |||
3096 | if (width() < e->oldSize().width() && !m_view->wrapCursor()) { | 3096 | if (width() < e->oldSize().width() && !view()->wrapCursor()) { | ||
3097 | // May have to restrain cursor to new smaller width... | 3097 | // May have to restrain cursor to new smaller width... | ||
3098 | if (m_cursor.column() > doc()->lineLength(m_cursor.line())) { | 3098 | if (m_cursor.column() > doc()->lineLength(m_cursor.line())) { | ||
3099 | KateTextLayout thisLine = currentLayout(); | 3099 | KateTextLayout thisLine = currentLayout(); | ||
3100 | 3100 | | |||
3101 | KTextEditor::Cursor newCursor(m_cursor.line(), thisLine.endCol() + ((width() - thisLine.xOffset() - (thisLine.width() - m_startX)) / renderer()->spaceWidth()) - 1); | 3101 | KTextEditor::Cursor newCursor(m_cursor.line(), thisLine.endCol() + ((width() - thisLine.xOffset() - (thisLine.width() - startX())) / renderer()->spaceWidth()) - 1); | ||
3102 | if (newCursor.column() < m_cursor.column()) { | 3102 | if (newCursor.column() < m_cursor.column()) { | ||
3103 | updateCursor(newCursor); | 3103 | updateCursor(newCursor); | ||
3104 | } | 3104 | } | ||
3105 | } | 3105 | } | ||
3106 | } | 3106 | } | ||
3107 | 3107 | | |||
3108 | if (expandedVertically) { | 3108 | if (expandedVertically) { | ||
3109 | KTextEditor::Cursor max = maxStartPos(); | 3109 | KTextEditor::Cursor max = maxStartPos(); | ||
3110 | if (startPos() > max) { | 3110 | if (startPos() > max) { | ||
3111 | scrollPos(max); | 3111 | scrollPos(max); | ||
3112 | return; // already fired displayRangeChanged | 3112 | return; // already fired displayRangeChanged | ||
3113 | } | 3113 | } | ||
3114 | } | 3114 | } | ||
3115 | emit m_view->displayRangeChanged(m_view); | 3115 | emit view()->displayRangeChanged(m_view); | ||
3116 | } | 3116 | } | ||
3117 | 3117 | | |||
3118 | void KateViewInternal::scrollTimeout() | 3118 | void KateViewInternal::scrollTimeout() | ||
3119 | { | 3119 | { | ||
3120 | if (m_scrollX || m_scrollY) { | 3120 | if (m_scrollX || m_scrollY) { | ||
3121 | scrollLines(startPos().line() + (m_scrollY / (int) renderer()->lineHeight())); | 3121 | scrollLines(startLine() + (m_scrollY / (int) renderer()->lineHeight())); | ||
3122 | placeCursor(QPoint(m_mouseX, m_mouseY), true); | 3122 | placeCursor(QPoint(m_mouseX, m_mouseY), true); | ||
3123 | } | 3123 | } | ||
3124 | } | 3124 | } | ||
3125 | 3125 | | |||
3126 | void KateViewInternal::cursorTimeout() | 3126 | void KateViewInternal::cursorTimeout() | ||
3127 | { | 3127 | { | ||
3128 | if (!debugPainting && m_currentInputMode->blinkCaret()) { | 3128 | if (!debugPainting && m_currentInputMode->blinkCaret()) { | ||
3129 | renderer()->setDrawCaret(!renderer()->drawCaret()); | 3129 | renderer()->setDrawCaret(!renderer()->drawCaret()); | ||
Show All 35 Lines | 3164 | if (QApplication::cursorFlashTime() > 0) { | |||
3165 | m_cursorTimer.start(QApplication::cursorFlashTime() / 2); | 3165 | m_cursorTimer.start(QApplication::cursorFlashTime() / 2); | ||
3166 | } | 3166 | } | ||
3167 | 3167 | | |||
3168 | paintCursor(); | 3168 | paintCursor(); | ||
3169 | 3169 | | |||
3170 | doc()->setActiveView(m_view); | 3170 | doc()->setActiveView(m_view); | ||
3171 | 3171 | | |||
3172 | // this will handle focus stuff in kateview | 3172 | // this will handle focus stuff in kateview | ||
3173 | m_view->slotGotFocus(); | 3173 | view()->slotGotFocus(); | ||
3174 | } | 3174 | } | ||
3175 | 3175 | | |||
3176 | void KateViewInternal::focusOutEvent(QFocusEvent *) | 3176 | void KateViewInternal::focusOutEvent(QFocusEvent *) | ||
3177 | { | 3177 | { | ||
3178 | //if (m_view->isCompletionActive()) | 3178 | //if (view()->isCompletionActive()) | ||
3179 | //m_view->abortCompletion(); | 3179 | //view()->abortCompletion(); | ||
3180 | 3180 | | |||
3181 | m_cursorTimer.stop(); | 3181 | m_cursorTimer.stop(); | ||
3182 | m_view->renderer()->setDrawCaret(true); | 3182 | view()->renderer()->setDrawCaret(true); | ||
3183 | paintCursor(); | 3183 | paintCursor(); | ||
3184 | 3184 | | |||
3185 | m_textHintTimer.stop(); | 3185 | m_textHintTimer.stop(); | ||
3186 | 3186 | | |||
3187 | m_view->slotLostFocus(); | 3187 | view()->slotLostFocus(); | ||
3188 | } | 3188 | } | ||
3189 | 3189 | | |||
3190 | void KateViewInternal::doDrag() | 3190 | void KateViewInternal::doDrag() | ||
3191 | { | 3191 | { | ||
3192 | m_dragInfo.state = diDragging; | 3192 | m_dragInfo.state = diDragging; | ||
3193 | m_dragInfo.dragObject = new QDrag(this); | 3193 | m_dragInfo.dragObject = new QDrag(this); | ||
3194 | QMimeData *mimeData = new QMimeData(); | 3194 | QMimeData *mimeData = new QMimeData(); | ||
3195 | mimeData->setText(m_view->selectionText()); | 3195 | mimeData->setText(view()->selectionText()); | ||
3196 | m_dragInfo.dragObject->setMimeData(mimeData); | 3196 | m_dragInfo.dragObject->setMimeData(mimeData); | ||
3197 | m_dragInfo.dragObject->start(Qt::MoveAction); | 3197 | m_dragInfo.dragObject->start(Qt::MoveAction); | ||
3198 | } | 3198 | } | ||
3199 | 3199 | | |||
3200 | void KateViewInternal::dragEnterEvent(QDragEnterEvent *event) | 3200 | void KateViewInternal::dragEnterEvent(QDragEnterEvent *event) | ||
3201 | { | 3201 | { | ||
3202 | if (event->source() == this) { | 3202 | if (event->source() == this) { | ||
3203 | event->setDropAction(Qt::MoveAction); | 3203 | event->setDropAction(Qt::MoveAction); | ||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Line(s) | 3248 | if (event->mimeData()->hasText() && doc()->isReadWrite()) { | |||
3251 | 3251 | | |||
3252 | // is the source our own document? | 3252 | // is the source our own document? | ||
3253 | bool priv = false; | 3253 | bool priv = false; | ||
3254 | if (KateViewInternal *vi = qobject_cast<KateViewInternal *>(event->source())) { | 3254 | if (KateViewInternal *vi = qobject_cast<KateViewInternal *>(event->source())) { | ||
3255 | priv = doc()->ownedView(vi->m_view); | 3255 | priv = doc()->ownedView(vi->m_view); | ||
3256 | } | 3256 | } | ||
3257 | 3257 | | |||
3258 | // dropped on a text selection area? | 3258 | // dropped on a text selection area? | ||
3259 | bool selected = m_view->cursorSelected(m_cursor); | 3259 | bool selected = view()->cursorSelected(m_cursor); | ||
3260 | 3260 | | |||
3261 | fixDropEvent(event); | 3261 | fixDropEvent(event); | ||
3262 | 3262 | | |||
3263 | if (priv && selected && event->dropAction() != Qt::CopyAction) { | 3263 | if (priv && selected && event->dropAction() != Qt::CopyAction) { | ||
3264 | // this is a drag that we started and dropped on our selection | 3264 | // this is a drag that we started and dropped on our selection | ||
3265 | // ignore this case | 3265 | // ignore this case | ||
3266 | return; | 3266 | return; | ||
3267 | } | 3267 | } | ||
3268 | 3268 | | |||
3269 | // fix the cursor position before editStart(), so that it is correctly | 3269 | // fix the cursor position before editStart(), so that it is correctly | ||
3270 | // stored for the undo action | 3270 | // stored for the undo action | ||
3271 | KTextEditor::Cursor targetCursor(m_cursor); // backup current cursor | 3271 | KTextEditor::Cursor targetCursor(m_cursor); // backup current cursor | ||
3272 | int selectionWidth = m_view->selectionRange().columnWidth(); // for block selection | 3272 | int selectionWidth = view()->selectionRange().columnWidth(); // for block selection | ||
3273 | int selectionHeight = m_view->selectionRange().numberOfLines(); // for block selection | 3273 | int selectionHeight = view()->selectionRange().numberOfLines(); // for block selection | ||
3274 | 3274 | | |||
3275 | if (event->dropAction() != Qt::CopyAction) { | 3275 | if (event->dropAction() != Qt::CopyAction) { | ||
3276 | editSetCursor(m_view->selectionRange().end()); | 3276 | editSetCursor(view()->selectionRange().end()); | ||
3277 | } else { | 3277 | } else { | ||
3278 | m_view->clearSelection(); | 3278 | view()->clearSelection(); | ||
3279 | } | 3279 | } | ||
3280 | 3280 | | |||
3281 | // use one transaction | 3281 | // use one transaction | ||
3282 | doc()->editStart(); | 3282 | doc()->editStart(); | ||
3283 | 3283 | | |||
3284 | // on move: remove selected text; on copy: duplicate text | 3284 | // on move: remove selected text; on copy: duplicate text | ||
3285 | doc()->insertText(targetCursor, text, m_view->blockSelection()); | 3285 | doc()->insertText(targetCursor, text, view()->blockSelection()); | ||
3286 | 3286 | | |||
3287 | KTextEditor::DocumentCursor startCursor(doc(), targetCursor); | 3287 | KTextEditor::DocumentCursor startCursor(doc(), targetCursor); | ||
3288 | KTextEditor::DocumentCursor endCursor1(doc(), targetCursor); | 3288 | KTextEditor::DocumentCursor endCursor1(doc(), targetCursor); | ||
3289 | const int textLength = text.length(); | 3289 | const int textLength = text.length(); | ||
3290 | 3290 | | |||
3291 | if (event->dropAction() != Qt::CopyAction) { | 3291 | if (event->dropAction() != Qt::CopyAction) { | ||
3292 | m_view->removeSelectedText(); | 3292 | view()->removeSelectedText(); | ||
3293 | if (m_cursor.toCursor() < startCursor.toCursor()) { | 3293 | if (m_cursor.toCursor() < startCursor.toCursor()) { | ||
3294 | startCursor.move(-textLength); | 3294 | startCursor.move(-textLength); | ||
3295 | endCursor1.move(-textLength); | 3295 | endCursor1.move(-textLength); | ||
3296 | } | 3296 | } | ||
3297 | } | 3297 | } | ||
3298 | 3298 | | |||
3299 | if (!m_view->blockSelection()) { | 3299 | if (!view()->blockSelection()) { | ||
3300 | endCursor1.move(textLength); | 3300 | endCursor1.move(textLength); | ||
3301 | } else { | 3301 | } else { | ||
3302 | endCursor1.setColumn(startCursor.column() + selectionWidth); | 3302 | endCursor1.setColumn(startCursor.column() + selectionWidth); | ||
3303 | endCursor1.setLine(startCursor.line() + selectionHeight); | 3303 | endCursor1.setLine(startCursor.line() + selectionHeight); | ||
3304 | } | 3304 | } | ||
3305 | 3305 | | |||
3306 | KTextEditor::Cursor endCursor(endCursor1); | 3306 | KTextEditor::Cursor endCursor(endCursor1); | ||
3307 | qCDebug(LOG_KTE) << startCursor << "---(" << textLength << ")---" << endCursor; | 3307 | qCDebug(LOG_KTE) << startCursor << "---(" << textLength << ")---" << endCursor; | ||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Line(s) | 3351 | if (e->orientation() == Qt::Vertical) { | |||
3367 | // do scroll | 3367 | // do scroll | ||
3368 | scrollViewLines(int(offset) + extraAccumulated); | 3368 | scrollViewLines(int(offset) + extraAccumulated); | ||
3369 | e->accept(); | 3369 | e->accept(); | ||
3370 | } | 3370 | } | ||
3371 | 3371 | | |||
3372 | // handle horizontal scrolling via the scrollbar | 3372 | // handle horizontal scrolling via the scrollbar | ||
3373 | if (e->orientation() == Qt::Horizontal) { | 3373 | if (e->orientation() == Qt::Horizontal) { | ||
3374 | // if we have dyn word wrap, we should ignore the scroll events | 3374 | // if we have dyn word wrap, we should ignore the scroll events | ||
3375 | if (m_view->dynWordWrap()) { | 3375 | if (view()->dynWordWrap()) { | ||
3376 | e->accept(); | 3376 | e->accept(); | ||
3377 | return; | 3377 | return; | ||
3378 | } | 3378 | } | ||
3379 | 3379 | | |||
3380 | QWheelEvent copy = *e; | 3380 | QWheelEvent copy = *e; | ||
3381 | QApplication::sendEvent(m_columnScroll, ©); | 3381 | QApplication::sendEvent(m_columnScroll, ©); | ||
3382 | if (copy.isAccepted()) { | 3382 | if (copy.isAccepted()) { | ||
3383 | e->accept(); | 3383 | e->accept(); | ||
Show All 29 Lines | 3412 | if (p.x() < s_scrollMargin) { | |||
3413 | dx = p.x() - s_scrollMargin; | 3413 | dx = p.x() - s_scrollMargin; | ||
3414 | } else if (p.x() > width() - s_scrollMargin) { | 3414 | } else if (p.x() > width() - s_scrollMargin) { | ||
3415 | dx = s_scrollMargin - (width() - p.x()); | 3415 | dx = s_scrollMargin - (width() - p.x()); | ||
3416 | } | 3416 | } | ||
3417 | 3417 | | |||
3418 | dy /= 4; | 3418 | dy /= 4; | ||
3419 | 3419 | | |||
3420 | if (dy) { | 3420 | if (dy) { | ||
3421 | scrollLines(startPos().line() + dy); | 3421 | scrollLines(startLine() + dy); | ||
3422 | } | 3422 | } | ||
3423 | 3423 | | |||
3424 | if (columnScrollingPossible() && dx) { | 3424 | if (columnScrollingPossible() && dx) { | ||
3425 | scrollColumns(qMin(m_startX + dx, m_columnScroll->maximum())); | 3425 | scrollColumns(qMin(startX() + dx, m_columnScroll->maximum())); | ||
3426 | } | 3426 | } | ||
3427 | 3427 | | |||
3428 | if (!dy && !dx) { | 3428 | if (!dy && !dx) { | ||
3429 | stopDragScroll(); | 3429 | stopDragScroll(); | ||
3430 | } | 3430 | } | ||
3431 | } | 3431 | } | ||
3432 | 3432 | | |||
3433 | void KateViewInternal::registerTextHintProvider(KTextEditor::TextHintProvider *provider) | 3433 | void KateViewInternal::registerTextHintProvider(KTextEditor::TextHintProvider *provider) | ||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | 3476 | { | |||
3477 | editSessionNumber++; | 3477 | editSessionNumber++; | ||
3478 | 3478 | | |||
3479 | if (editSessionNumber > 1) { | 3479 | if (editSessionNumber > 1) { | ||
3480 | return; | 3480 | return; | ||
3481 | } | 3481 | } | ||
3482 | 3482 | | |||
3483 | editIsRunning = true; | 3483 | editIsRunning = true; | ||
3484 | editOldCursor = m_cursor; | 3484 | editOldCursor = m_cursor; | ||
3485 | editOldSelection = m_view->selectionRange(); | 3485 | editOldSelection = view()->selectionRange(); | ||
3486 | } | 3486 | } | ||
3487 | 3487 | | |||
3488 | void KateViewInternal::editEnd(int editTagLineStart, int editTagLineEnd, bool tagFrom) | 3488 | void KateViewInternal::editEnd(int editTagLineStart, int editTagLineEnd, bool tagFrom) | ||
3489 | { | 3489 | { | ||
3490 | if (editSessionNumber == 0) { | 3490 | if (editSessionNumber == 0) { | ||
3491 | return; | 3491 | return; | ||
3492 | } | 3492 | } | ||
3493 | 3493 | | |||
3494 | editSessionNumber--; | 3494 | editSessionNumber--; | ||
3495 | 3495 | | |||
3496 | if (editSessionNumber > 0) { | 3496 | if (editSessionNumber > 0) { | ||
3497 | return; | 3497 | return; | ||
3498 | } | 3498 | } | ||
3499 | 3499 | | |||
3500 | // fix start position, might have moved from column 0 | 3500 | // fix start position, might have moved from column 0 | ||
3501 | // try to clever calculate the right start column for the tricky dyn word wrap case | 3501 | // try to clever calculate the right start column for the tricky dyn word wrap case | ||
3502 | int col = 0; | 3502 | int col = 0; | ||
3503 | if (m_view->dynWordWrap()) { | 3503 | if (view()->dynWordWrap()) { | ||
3504 | if (KateLineLayoutPtr layout = cache()->line(m_startPos.line())) { | 3504 | if (KateLineLayoutPtr layout = cache()->line(startLine())) { | ||
3505 | int index = layout->viewLineForColumn(m_startPos.column()); | 3505 | int index = layout->viewLineForColumn(startPos().column()); | ||
3506 | if (index >= 0 && index < layout->viewLineCount()) { | 3506 | if (index >= 0 && index < layout->viewLineCount()) { | ||
3507 | col = layout->viewLine(index).startCol(); | 3507 | col = layout->viewLine(index).startCol(); | ||
3508 | } | 3508 | } | ||
3509 | } | 3509 | } | ||
3510 | } | 3510 | } | ||
3511 | m_startPos.setPosition(m_startPos.line(), col); | 3511 | m_startPos.setPosition(startLine(), col); | ||
3512 | 3512 | | |||
3513 | if (tagFrom && (editTagLineStart <= int(m_view->textFolding().visibleLineToLine(startLine())))) { | 3513 | if (tagFrom && (editTagLineStart <= int(view()->textFolding().visibleLineToLine(startLine())))) { | ||
3514 | tagAll(); | 3514 | tagAll(); | ||
3515 | } else { | 3515 | } else { | ||
3516 | tagLines(editTagLineStart, tagFrom ? qMax(doc()->lastLine() + 1, editTagLineEnd) : editTagLineEnd, true); | 3516 | tagLines(editTagLineStart, tagFrom ? qMax(doc()->lastLine() + 1, editTagLineEnd) : editTagLineEnd, true); | ||
3517 | } | 3517 | } | ||
3518 | 3518 | | |||
3519 | if (editOldCursor == m_cursor.toCursor()) { | 3519 | if (editOldCursor == m_cursor.toCursor()) { | ||
3520 | updateBracketMarks(); | 3520 | updateBracketMarks(); | ||
3521 | } | 3521 | } | ||
Show All 9 Lines | 3529 | if (m_cursor.line() >= editTagLineStart && m_cursor.line() <= editTagLineEnd) { | |||
3531 | updateCursor(m_cursor, true); | 3531 | updateCursor(m_cursor, true); | ||
3532 | } | 3532 | } | ||
3533 | } | 3533 | } | ||
3534 | 3534 | | |||
3535 | /** | 3535 | /** | ||
3536 | * selection changed? | 3536 | * selection changed? | ||
3537 | * fixes bug 316226 | 3537 | * fixes bug 316226 | ||
3538 | */ | 3538 | */ | ||
3539 | if (editOldSelection != m_view->selectionRange() | 3539 | if (editOldSelection != view()->selectionRange() | ||
3540 | || (editOldSelection.isValid() && !editOldSelection.isEmpty() && !(editTagLineStart > editOldSelection.end().line() && editTagLineEnd < editOldSelection.start().line()))) { | 3540 | || (editOldSelection.isValid() && !editOldSelection.isEmpty() && !(editTagLineStart > editOldSelection.end().line() && editTagLineEnd < editOldSelection.start().line()))) { | ||
3541 | emit m_view->selectionChanged(m_view); | 3541 | emit view()->selectionChanged(m_view); | ||
3542 | } | 3542 | } | ||
3543 | 3543 | | |||
3544 | editIsRunning = false; | 3544 | editIsRunning = false; | ||
3545 | } | 3545 | } | ||
3546 | 3546 | | |||
3547 | void KateViewInternal::editSetCursor(const KTextEditor::Cursor &_cursor) | 3547 | void KateViewInternal::editSetCursor(const KTextEditor::Cursor &_cursor) | ||
3548 | { | 3548 | { | ||
3549 | if (m_cursor.toCursor() != _cursor) { | 3549 | if (m_cursor.toCursor() != _cursor) { | ||
3550 | m_cursor.setPosition(_cursor); | 3550 | m_cursor.setPosition(_cursor); | ||
3551 | } | 3551 | } | ||
3552 | } | 3552 | } | ||
3553 | //END | 3553 | //END | ||
3554 | 3554 | | |||
3555 | void KateViewInternal::viewSelectionChanged() | 3555 | void KateViewInternal::viewSelectionChanged() | ||
3556 | { | 3556 | { | ||
3557 | if (!m_view->selection()) { | 3557 | if (!view()->selection()) { | ||
3558 | m_selectAnchor = KTextEditor::Cursor::invalid(); | 3558 | m_selectAnchor = KTextEditor::Cursor::invalid(); | ||
3559 | } else { | 3559 | } else { | ||
3560 | m_selectAnchor = m_view->selectionRange().start(); | 3560 | m_selectAnchor = view()->selectionRange().start(); | ||
3561 | } | 3561 | } | ||
3562 | // Do NOT nuke the entire range! The reason is that a shift+DC selection | 3562 | // Do NOT nuke the entire range! The reason is that a shift+DC selection | ||
3563 | // might (correctly) set the range to be empty (i.e. start() == end()), and | 3563 | // might (correctly) set the range to be empty (i.e. start() == end()), and | ||
3564 | // subsequent dragging might shrink the selection into non-existence. When | 3564 | // subsequent dragging might shrink the selection into non-existence. When | ||
3565 | // this happens, we use the cached end to restore the cached start so that | 3565 | // this happens, we use the cached end to restore the cached start so that | ||
3566 | // updateSelection is not confused. See also comments in updateSelection. | 3566 | // updateSelection is not confused. See also comments in updateSelection. | ||
3567 | m_selectionCached.setStart(KTextEditor::Cursor::invalid()); | 3567 | m_selectionCached.setStart(KTextEditor::Cursor::invalid()); | ||
3568 | } | 3568 | } | ||
3569 | 3569 | | |||
3570 | KateLayoutCache *KateViewInternal::cache() const | 3570 | KateLayoutCache *KateViewInternal::cache() const | ||
3571 | { | 3571 | { | ||
3572 | return m_layoutCache; | 3572 | return m_layoutCache; | ||
3573 | } | 3573 | } | ||
3574 | 3574 | | |||
3575 | KTextEditor::Cursor KateViewInternal::toRealCursor(const KTextEditor::Cursor &virtualCursor) const | 3575 | KTextEditor::Cursor KateViewInternal::toRealCursor(const KTextEditor::Cursor &virtualCursor) const | ||
3576 | { | 3576 | { | ||
3577 | return KTextEditor::Cursor(m_view->textFolding().visibleLineToLine(virtualCursor.line()), virtualCursor.column()); | 3577 | return KTextEditor::Cursor(view()->textFolding().visibleLineToLine(virtualCursor.line()), virtualCursor.column()); | ||
3578 | } | 3578 | } | ||
3579 | 3579 | | |||
3580 | KTextEditor::Cursor KateViewInternal::toVirtualCursor(const KTextEditor::Cursor &realCursor) const | 3580 | KTextEditor::Cursor KateViewInternal::toVirtualCursor(const KTextEditor::Cursor &realCursor) const | ||
3581 | { | 3581 | { | ||
3582 | /** | 3582 | /** | ||
3583 | * only convert valid lines, folding doesn't like invalid input! | 3583 | * only convert valid lines, folding doesn't like invalid input! | ||
3584 | * don't validate whole cursor, column might be -1 | 3584 | * don't validate whole cursor, column might be -1 | ||
3585 | */ | 3585 | */ | ||
3586 | if (realCursor.line() < 0) { | 3586 | if (realCursor.line() < 0) { | ||
3587 | return KTextEditor::Cursor::invalid(); | 3587 | return KTextEditor::Cursor::invalid(); | ||
3588 | } | 3588 | } | ||
3589 | 3589 | | |||
3590 | return KTextEditor::Cursor(m_view->textFolding().lineToVisibleLine(realCursor.line()), realCursor.column()); | 3590 | return KTextEditor::Cursor(view()->textFolding().lineToVisibleLine(realCursor.line()), realCursor.column()); | ||
3591 | } | 3591 | } | ||
3592 | 3592 | | |||
3593 | KateRenderer *KateViewInternal::renderer() const | 3593 | KateRenderer *KateViewInternal::renderer() const | ||
3594 | { | 3594 | { | ||
3595 | return m_view->renderer(); | 3595 | return view()->renderer(); | ||
3596 | } | 3596 | } | ||
3597 | 3597 | | |||
3598 | void KateViewInternal::mouseMoved() | 3598 | void KateViewInternal::mouseMoved() | ||
3599 | { | 3599 | { | ||
3600 | m_view->notifyMousePositionChanged(m_mouse); | 3600 | view()->notifyMousePositionChanged(m_mouse); | ||
3601 | m_view->updateRangesIn(KTextEditor::Attribute::ActivateMouseIn); | 3601 | view()->updateRangesIn(KTextEditor::Attribute::ActivateMouseIn); | ||
3602 | } | 3602 | } | ||
3603 | 3603 | | |||
3604 | void KateViewInternal::cursorMoved() | 3604 | void KateViewInternal::cursorMoved() | ||
3605 | { | 3605 | { | ||
3606 | m_view->updateRangesIn(KTextEditor::Attribute::ActivateCaretIn); | 3606 | view()->updateRangesIn(KTextEditor::Attribute::ActivateCaretIn); | ||
3607 | 3607 | | |||
3608 | #ifndef QT_NO_ACCESSIBILITY | 3608 | #ifndef QT_NO_ACCESSIBILITY | ||
3609 | if (QAccessible::isActive()) { | 3609 | if (QAccessible::isActive()) { | ||
3610 | QAccessibleTextCursorEvent ev(this, static_cast<KateViewAccessible *>(QAccessible::queryAccessibleInterface(this))->positionFromCursor(this, m_cursor)); | 3610 | QAccessibleTextCursorEvent ev(this, static_cast<KateViewAccessible *>(QAccessible::queryAccessibleInterface(this))->positionFromCursor(this, m_cursor)); | ||
3611 | QAccessible::updateAccessibility(&ev); | 3611 | QAccessible::updateAccessibility(&ev); | ||
3612 | } | 3612 | } | ||
3613 | #endif | 3613 | #endif | ||
3614 | } | 3614 | } | ||
3615 | 3615 | | |||
3616 | bool KateViewInternal::rangeAffectsView(const KTextEditor::Range &range, bool realCursors) const | 3616 | bool KateViewInternal::rangeAffectsView(const KTextEditor::Range &range, bool realCursors) const | ||
3617 | { | 3617 | { | ||
3618 | int startLine = m_startPos.line(); | 3618 | int startLine = KateViewInternal::startLine(); | ||
3619 | int endLine = startLine + (int)m_visibleLineCount; | 3619 | int endLine = startLine + (int)m_visibleLineCount; | ||
3620 | 3620 | | |||
3621 | if (realCursors) { | 3621 | if (realCursors) { | ||
3622 | startLine = (int)m_view->textFolding().visibleLineToLine(startLine); | 3622 | startLine = (int)view()->textFolding().visibleLineToLine(startLine); | ||
3623 | endLine = (int)m_view->textFolding().visibleLineToLine(endLine); | 3623 | endLine = (int)view()->textFolding().visibleLineToLine(endLine); | ||
3624 | } | 3624 | } | ||
3625 | 3625 | | |||
3626 | return (range.end().line() >= startLine) || (range.start().line() <= endLine); | 3626 | return (range.end().line() >= startLine) || (range.start().line() <= endLine); | ||
3627 | } | 3627 | } | ||
3628 | 3628 | | |||
3629 | //BEGIN IM INPUT STUFF | 3629 | //BEGIN IM INPUT STUFF | ||
3630 | QVariant KateViewInternal::inputMethodQuery(Qt::InputMethodQuery query) const | 3630 | QVariant KateViewInternal::inputMethodQuery(Qt::InputMethodQuery query) const | ||
3631 | { | 3631 | { | ||
Show All 16 Lines | 3647 | case Qt::ImFont: | |||
3648 | return renderer()->currentFont(); | 3648 | return renderer()->currentFont(); | ||
3649 | 3649 | | |||
3650 | case Qt::ImCursorPosition: | 3650 | case Qt::ImCursorPosition: | ||
3651 | return m_cursor.column(); | 3651 | return m_cursor.column(); | ||
3652 | 3652 | | |||
3653 | case Qt::ImAnchorPosition: | 3653 | case Qt::ImAnchorPosition: | ||
3654 | // If selectAnchor is at the same line, return the real anchor position | 3654 | // If selectAnchor is at the same line, return the real anchor position | ||
3655 | // Otherwise return the same position of cursor | 3655 | // Otherwise return the same position of cursor | ||
3656 | if (m_view->selection() && m_selectAnchor.line() == m_cursor.line()) { | 3656 | if (view()->selection() && m_selectAnchor.line() == m_cursor.line()) { | ||
3657 | return m_selectAnchor.column(); | 3657 | return m_selectAnchor.column(); | ||
3658 | } else { | 3658 | } else { | ||
3659 | return m_cursor.column(); | 3659 | return m_cursor.column(); | ||
3660 | } | 3660 | } | ||
3661 | 3661 | | |||
3662 | case Qt::ImSurroundingText: | 3662 | case Qt::ImSurroundingText: | ||
3663 | if (Kate::TextLine l = doc()->kateTextLine(m_cursor.line())) { | 3663 | if (Kate::TextLine l = doc()->kateTextLine(m_cursor.line())) { | ||
3664 | return l->string(); | 3664 | return l->string(); | ||
3665 | } else { | 3665 | } else { | ||
3666 | return QString(); | 3666 | return QString(); | ||
3667 | } | 3667 | } | ||
3668 | 3668 | | |||
3669 | case Qt::ImCurrentSelection: | 3669 | case Qt::ImCurrentSelection: | ||
3670 | if (m_view->selection()) { | 3670 | if (view()->selection()) { | ||
3671 | return m_view->selectionText(); | 3671 | return view()->selectionText(); | ||
3672 | } else { | 3672 | } else { | ||
3673 | return QString(); | 3673 | return QString(); | ||
3674 | } | 3674 | } | ||
3675 | default: | 3675 | default: | ||
3676 | /* values: ImMaximumTextLength */ | 3676 | /* values: ImMaximumTextLength */ | ||
3677 | break; | 3677 | break; | ||
3678 | } | 3678 | } | ||
3679 | 3679 | | |||
Show All 15 Lines | 3684 | { | |||
3695 | 3695 | | |||
3696 | if (!m_imPreeditRange->toRange().isEmpty()) { | 3696 | if (!m_imPreeditRange->toRange().isEmpty()) { | ||
3697 | doc()->inputMethodStart(); | 3697 | doc()->inputMethodStart(); | ||
3698 | doc()->removeText(*m_imPreeditRange); | 3698 | doc()->removeText(*m_imPreeditRange); | ||
3699 | doc()->inputMethodEnd(); | 3699 | doc()->inputMethodEnd(); | ||
3700 | } | 3700 | } | ||
3701 | 3701 | | |||
3702 | if (!e->commitString().isEmpty() || e->replacementLength()) { | 3702 | if (!e->commitString().isEmpty() || e->replacementLength()) { | ||
3703 | m_view->removeSelectedText(); | 3703 | view()->removeSelectedText(); | ||
3704 | 3704 | | |||
3705 | KTextEditor::Range preeditRange = *m_imPreeditRange; | 3705 | KTextEditor::Range preeditRange = *m_imPreeditRange; | ||
3706 | 3706 | | |||
3707 | KTextEditor::Cursor start(m_imPreeditRange->start().line(), m_imPreeditRange->start().column() + e->replacementStart()); | 3707 | KTextEditor::Cursor start(m_imPreeditRange->start().line(), m_imPreeditRange->start().column() + e->replacementStart()); | ||
3708 | KTextEditor::Cursor removeEnd = start + KTextEditor::Cursor(0, e->replacementLength()); | 3708 | KTextEditor::Cursor removeEnd = start + KTextEditor::Cursor(0, e->replacementLength()); | ||
3709 | 3709 | | |||
3710 | doc()->editStart(); | 3710 | doc()->editStart(); | ||
3711 | if (start != removeEnd) { | 3711 | if (start != removeEnd) { | ||
▲ Show 20 Lines • Show All 80 Lines • ▼ Show 20 Line(s) | |||||
3792 | //END IM INPUT STUFF | 3792 | //END IM INPUT STUFF | ||
3793 | 3793 | | |||
3794 | void KateViewInternal::flashChar(const KTextEditor::Cursor &pos, KTextEditor::Attribute::Ptr attribute) | 3794 | void KateViewInternal::flashChar(const KTextEditor::Cursor &pos, KTextEditor::Attribute::Ptr attribute) | ||
3795 | { | 3795 | { | ||
3796 | Q_ASSERT(pos.isValid()); | 3796 | Q_ASSERT(pos.isValid()); | ||
3797 | Q_ASSERT(attribute.constData()); | 3797 | Q_ASSERT(attribute.constData()); | ||
3798 | 3798 | | |||
3799 | // if line is folded away, do nothing | 3799 | // if line is folded away, do nothing | ||
3800 | if (!m_view->textFolding().isLineVisible(pos.line())) { | 3800 | if (!view()->textFolding().isLineVisible(pos.line())) { | ||
3801 | return; | 3801 | return; | ||
3802 | } | 3802 | } | ||
3803 | 3803 | | |||
3804 | KTextEditor::Range range(pos, KTextEditor::Cursor(pos.line(), pos.column() + 1)); | 3804 | KTextEditor::Range range(pos, KTextEditor::Cursor(pos.line(), pos.column() + 1)); | ||
3805 | if (m_textAnimation) { | 3805 | if (m_textAnimation) { | ||
3806 | m_textAnimation->deleteLater(); | 3806 | m_textAnimation->deleteLater(); | ||
3807 | } | 3807 | } | ||
3808 | m_textAnimation = new KateTextAnimation(range, attribute, this); | 3808 | m_textAnimation = new KateTextAnimation(range, attribute, this); | ||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Line(s) | 3834 | { | |||
3854 | 3854 | | |||
3855 | return globalNoteRect; | 3855 | return globalNoteRect; | ||
3856 | } | 3856 | } | ||
3857 | 3857 | | |||
3858 | KateInlineNoteData KateViewInternal::inlineNoteAt(const QPoint& globalPos) const | 3858 | KateInlineNoteData KateViewInternal::inlineNoteAt(const QPoint& globalPos) const | ||
3859 | { | 3859 | { | ||
3860 | // compute the associated cursor to get the right line | 3860 | // compute the associated cursor to get the right line | ||
3861 | const int line = coordinatesToCursor(mapFromGlobal(globalPos)).line(); | 3861 | const int line = coordinatesToCursor(mapFromGlobal(globalPos)).line(); | ||
3862 | const auto inlineNotes = m_view->inlineNotes(line); | 3862 | const auto inlineNotes = view()->inlineNotes(line); | ||
3863 | // loop over all notes and check if the point is inside it | 3863 | // loop over all notes and check if the point is inside it | ||
3864 | foreach (const auto& note, inlineNotes) { | 3864 | foreach (const auto& note, inlineNotes) { | ||
3865 | auto globalNoteRect = inlineNoteRect(note); | 3865 | auto globalNoteRect = inlineNoteRect(note); | ||
3866 | if (globalNoteRect.contains(globalPos)) { | 3866 | if (globalNoteRect.contains(globalPos)) { | ||
3867 | return note; | 3867 | return note; | ||
3868 | } | 3868 | } | ||
3869 | } | 3869 | } | ||
3870 | // none found -- return an invalid note | 3870 | // none found -- return an invalid note | ||
3871 | return {}; | 3871 | return {}; | ||
3872 | } | 3872 | } |