1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
#include "mark.h"
#include "basetexteditor.h"
#include <texteditor/basetexteditor.h>
#include "utils/position.h"
namespace Scripting {
namespace Internal {
Mark::Mark(BaseTextEditor *editor, int line, int column)
:m_editor(editor)
{
m_pos = convertPosition(line,column);
::TextEditor::BaseTextEditorWidget* widget = editor->textEditorWidget();
QTextDocument* document = widget->document();
connect( document, SIGNAL(contentsChange(int,int,int)), this, SLOT(update(int,int,int)));
}
int Mark::convertPosition(int line, int column)
{
const int origLine = m_editor->currentLine();
const int origColumn = m_editor->currentColumn();
m_editor->gotoLine(line, column);
const int result = m_editor->nativePosition();
m_editor->gotoLine(origLine, origColumn);
return result;
}
QString Mark::fileName() const
{
return m_editor->fileName();
}
int Mark::line() const
{
return m_editor->convertPosition(m_pos).line();
}
int Mark::column() const
{
return m_editor->convertPosition(m_pos).column();
}
void Mark::update(int from, int charsRemoved, int charsAdded)
{
if (m_pos <= from )
return;
const int delta = charsAdded - charsRemoved;
// Overlap the position
if ( m_pos <= from+charsRemoved )
m_pos = from;
else
m_pos += delta;
}
Mark *Mark::create(BaseTextEditor *editor, int line, int column)
{
// Object is owned by Qt Script
return new Mark(editor, line, column);
}
} // namespace Internal
} // namespace Scripting
|