Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kumir2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
2
Issues
2
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
kumir
kumir2
Commits
44346828
Commit
44346828
authored
Oct 08, 2014
by
Victor Yacovlev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Editor capable to work with soft-indents (Python etc.)
parent
a141ce01
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
226 additions
and
65 deletions
+226
-65
src/plugins/editor/editcommands.cpp
src/plugins/editor/editcommands.cpp
+7
-2
src/plugins/editor/editor.cpp
src/plugins/editor/editor.cpp
+6
-4
src/plugins/editor/editorplane.cpp
src/plugins/editor/editorplane.cpp
+80
-2
src/plugins/editor/editorplane.h
src/plugins/editor/editorplane.h
+1
-0
src/plugins/editor/textcursor.cpp
src/plugins/editor/textcursor.cpp
+132
-57
No files found.
src/plugins/editor/editcommands.cpp
View file @
44346828
...
...
@@ -29,11 +29,16 @@ void InsertCommand::redo()
return
;
cursorRow
=
cursor
->
row
();
cursorCol
=
cursor
->
column
();
bool
hardIndents
=
analizer
&&
!
analizer
->
plugin
()
->
indentsSignificant
();
doc
->
insertText
(
text
,
analizer
,
line
,
pos
,
blankLines
,
blankChars
);
QStringList
lines
=
text
.
split
(
"
\n
"
,
QString
::
KeepEmptyParts
);
if
(
lines
.
size
()
>
1
)
{
cursor
->
setRow
(
cursor
->
row
()
+
lines
.
size
()
-
1
);
cursor
->
setColumn
(
lines
.
last
().
length
()
+
doc
->
indentAt
(
cursor
->
row
())
*
2
);
int
newRow
=
cursor
->
row
()
+
lines
.
size
()
-
1
;
int
newCol
=
lines
.
last
().
length
();
if
(
hardIndents
)
newCol
+=
doc
->
indentAt
(
cursor
->
row
())
*
2
;
cursor
->
setRow
(
newRow
);
cursor
->
setColumn
(
newCol
);
}
else
{
cursor
->
setColumn
(
cursor
->
column
()
+
text
.
length
());
...
...
src/plugins/editor/editor.cpp
View file @
44346828
...
...
@@ -494,10 +494,12 @@ void EditorInstance::updateFromAnalizer()
}
doc_
->
at
(
i
).
multipleStatementsInLine
=
analizerInstance_
->
multipleStatementsInLine
(
i
);
doc_
->
marginAt
(
i
).
errors
.
clear
();
int
newIndent
=
doc_
->
indentAt
(
i
);
int
diffIndent
=
newIndent
-
oldIndent
;
if
(
cursor_
->
row
()
==
i
)
{
cursor_
->
setColumn
(
qMax
(
cursor_
->
column
()
+
2
*
diffIndent
,
0u
));
if
(
!
analizerPlugin_
->
indentsSignificant
())
{
int
newIndent
=
doc_
->
indentAt
(
i
);
int
diffIndent
=
newIndent
-
oldIndent
;
if
(
cursor_
->
row
()
==
i
)
{
cursor_
->
setColumn
(
qMax
(
cursor_
->
column
()
+
2
*
diffIndent
,
0u
));
}
}
}
for
(
int
i
=
0
;
i
<
errors
.
size
();
i
++
)
{
...
...
src/plugins/editor/editorplane.cpp
View file @
44346828
...
...
@@ -921,6 +921,11 @@ void EditorPlane::paintEvent(QPaintEvent *e)
// Paint a text
paintText
(
&
p
,
e
->
rect
().
translated
(
-
offset
()));
// Paint structure marks
if
(
editor_
->
analizer
()
&&
editor_
->
analizer
()
->
plugin
()
->
indentsSignificant
())
{
paintProgramStructureLines
(
&
p
,
e
->
rect
().
translated
(
-
offset
()));
}
// Paint a cursor
paintCursor
(
&
p
,
e
->
rect
().
translated
(
-
offset
()));
...
...
@@ -1429,6 +1434,8 @@ void EditorPlane::keyPressEvent(QKeyEvent *e)
if
(
moveToEnd
)
editor_
->
cursor
()
->
moveTo
(
editor_
->
cursor
()
->
row
(),
curText
.
length
());
QString
indent
;
int
proposedIndent
=
4
*
editor_
->
document
()
->
indentAt
(
editor_
->
cursor
()
->
row
()
+
1
);
indentSpaces
=
qMax
(
indentSpaces
,
proposedIndent
);
indent
.
fill
(
' '
,
indentSpaces
);
editor_
->
cursor
()
->
evaluateCommand
(
"
\n
"
+
indent
);
}
...
...
@@ -2079,9 +2086,10 @@ void EditorPlane::paintSelection(QPainter *p, const QRect &rect)
int
lh
=
lineHeight
();
int
cw
=
charWidth
();
bool
prevLineSelected
=
false
;
bool
hardIndent
=
editor_
->
analizer
()
&&
!
editor_
->
analizerPlugin_
->
indentsSignificant
();
for
(
int
i
=
startLine
;
i
<
endLine
+
1
;
i
++
)
{
if
(
i
<
editor_
->
document
()
->
linesCount
())
{
int
indentSpace
=
2
*
cw
*
editor_
->
document
()
->
indentAt
(
i
)
;
int
indentSpace
=
hardIndent
?
2
*
cw
*
editor_
->
document
()
->
indentAt
(
i
)
:
0
;
if
(
prevLineSelected
)
{
p
->
drawRect
(
0
,
i
*
lh
,
indentSpace
,
lh
);
}
...
...
@@ -2424,8 +2432,11 @@ void EditorPlane::paintText(QPainter *p, const QRect &rect)
// Draw text lines themselves
for
(
uint
i
=
startLine
;
i
<=
endLine
;
i
++
)
{
bool
hardIndents
=
editor_
->
analizer
()
&&
!
editor_
->
analizerPlugin_
->
indentsSignificant
();
// Indent count (in logical levels)
uint
indent
=
editor_
->
document
()
->
indentAt
(
i
)
;
uint
indent
=
hardIndents
?
editor_
->
document
()
->
indentAt
(
i
)
:
0u
;
// Bottom text bound (so 'i + 1' instead of 'i')
const
uint
y
=
(
i
+
1
)
*
lineHeight
();
...
...
@@ -2577,6 +2588,73 @@ void EditorPlane::paintText(QPainter *p, const QRect &rect)
}
// end for (uint i=startLine; i<=endLine; i++)
}
static
uint
countLeadingSpacesInString
(
const
QString
&
s
)
{
uint
result
=
0u
;
for
(
int
i
=
0
;
i
<
s
.
length
();
i
++
)
{
if
(
s
[
i
].
isSpace
())
{
result
++
;
}
else
{
break
;
}
}
return
result
;
}
void
EditorPlane
::
paintProgramStructureLines
(
QPainter
*
p
,
const
QRect
&
rect
)
{
p
->
save
();
const
QRgb
bg
=
palette
().
brush
(
QPalette
::
Base
).
color
().
rgb
();
const
QRgb
fg
=
palette
().
brush
(
QPalette
::
Text
).
color
().
rgb
();
const
QRgb
lc
=
qRgb
(
(
qRed
(
bg
)
+
qRed
(
fg
)
)
/
2
,
(
qGreen
(
bg
)
+
qGreen
(
fg
)
)
/
2
,
(
qBlue
(
bg
)
+
qBlue
(
fg
)
)
/
2
);
const
int
CW
=
charWidth
();
const
int
LH
=
lineHeight
();
const
QColor
linesColor
=
QColor
::
fromRgb
(
lc
);
p
->
setPen
(
linesColor
);
int
linesCount
=
editor_
->
document
()
->
linesCount
();
int
prevIndent
=
0
;
int
curIndent
=
0
;
int
nextIndent
=
0
;
int
x1
,
x2
,
y1
,
y2
;
for
(
int
l
=
0
;
l
<
linesCount
;
l
++
)
{
curIndent
=
editor_
->
document
()
->
indentAt
(
l
);
int
realIndent
=
countLeadingSpacesInString
(
editor_
->
document
()
->
textAt
(
l
))
/
4
;
curIndent
=
realIndent
;
prevIndent
=
0
;
if
(
l
>
0
)
{
prevIndent
=
editor_
->
document
()
->
indentAt
(
l
-
1
);
realIndent
=
countLeadingSpacesInString
(
editor_
->
document
()
->
textAt
(
l
-
1
))
/
4
;
prevIndent
=
realIndent
;
}
if
(
l
<
linesCount
-
1
)
{
nextIndent
=
editor_
->
document
()
->
indentAt
(
l
+
1
);
realIndent
=
countLeadingSpacesInString
(
editor_
->
document
()
->
textAt
(
l
+
1
))
/
4
;
nextIndent
=
realIndent
;
}
for
(
int
i
=
0
;
i
<
curIndent
;
i
++
)
{
x1
=
x2
=
i
*
4
*
CW
+
CW
/
2
;
y1
=
l
*
LH
;
y2
=
y1
+
LH
;
if
(
prevIndent
<
curIndent
&&
i
==
curIndent
-
1
)
y1
+=
LH
/
2
;
p
->
drawLine
(
x1
,
y1
,
x1
,
y2
);
if
(
i
+
1
>
nextIndent
&&
nextIndent
<
curIndent
)
{
x2
=
x1
+
CW
*
3
;
p
->
drawLine
(
x1
,
y2
,
x2
,
y2
);
}
}
}
p
->
restore
();
}
QPolygon
EditorPlane
::
errorUnderline
(
int
x
,
int
y
,
int
len
)
{
...
...
src/plugins/editor/editorplane.h
View file @
44346828
...
...
@@ -78,6 +78,7 @@ protected:
void
paintMarginText
(
QPainter
*
p
,
const
QRect
&
rect
);
void
paintCursor
(
QPainter
*
p
,
const
QRect
&
rect
);
void
paintText
(
QPainter
*
p
,
const
QRect
&
rect
);
void
paintProgramStructureLines
(
QPainter
*
p
,
const
QRect
&
rect
);
void
paintHiddenTextDelimeterLine
(
QPainter
*
p
);
void
paintSelection
(
QPainter
*
p
,
const
QRect
&
rect
);
void
paintRectSelection
(
QPainter
*
p
,
const
QRect
&
rect
);
...
...
src/plugins/editor/textcursor.cpp
View file @
44346828
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment