KTextEditor

vimode/range.cpp
1/*
2 SPDX-FileCopyrightText: 2008 Erlend Hamberg <ehamberg@gmail.com>
3 SPDX-FileCopyrightText: 2011 Svyatoslav Kuzmich <svatoslav1@gmail.com>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#include <ktexteditor/range.h>
9#include <vimode/range.h>
10
11using namespace KateVi;
12
13Range::Range()
14 : Range(-1, -1, -1, -1, InclusiveMotion)
15{
16}
17
18Range::Range(int slin, int scol, int elin, int ecol, MotionType inc)
19 : startLine(slin)
20 , startColumn(scol)
21 , endLine(elin)
22 , endColumn(ecol)
23 , motionType(inc)
24 , valid(true)
25 , jump(false)
26{
27}
28
29Range::Range(int elin, int ecol, MotionType inc)
30 : Range(-1, -1, elin, ecol, inc)
31{
32}
33
34Range::Range(const KTextEditor::Cursor c, MotionType mt)
35 : Range(-1, -1, c.line(), c.column(), mt)
36{
37}
38
39Range::Range(const KTextEditor::Cursor c1, const KTextEditor::Cursor c2, MotionType mt)
40 : Range(c1.line(), c1.column(), c2.line(), c2.column(), mt)
41{
42}
43
44void Range::normalize()
45{
46 int sl = startLine;
47 int el = endLine;
48 int sc = startColumn;
49 int ec = endColumn;
50
51 if (sl < el) {
52 startLine = sl;
53 startColumn = sc;
54 endLine = el;
55 endColumn = ec;
56 } else {
57 startLine = el;
58 endLine = sl;
59 if (sl != el) {
60 startColumn = ec;
61 endColumn = sc;
62 } else {
63 startColumn = qMin(sc, ec);
64 endColumn = qMax(sc, ec);
65 }
66 }
67}
68
69KTextEditor::Range Range::toEditorRange() const
70{
71 return KTextEditor::Range(startLine, startColumn, endLine, endColumn);
72}
73
74Range Range::invalid()
75{
76 Range r;
77 r.valid = false;
78 return r;
79}
80
81QDebug operator<<(QDebug s, const Range &range)
82{
83 s << "["
84 << " (" << range.startLine << ", " << range.startColumn << ")"
85 << " -> "
86 << " (" << range.endLine << ", " << range.endColumn << ")"
87 << "]"
88 << " (" << (range.motionType == InclusiveMotion ? "Inclusive" : "Exclusive") << ") (jump: " << (range.jump ? "true" : "false") << ")";
89 return s;
90}
The Cursor represents a position in a Document.
Definition cursor.h:75
An object representing a section of text, from one Cursor to another.
KCALENDARCORE_EXPORT QDataStream & operator<<(QDataStream &out, const KCalendarCore::Alarm::Ptr &)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 19 2024 12:00:29 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.