Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Marco Bubke
flatpak-qt-creator
Commits
8b3136f8
Commit
8b3136f8
authored
Jan 23, 2009
by
hjk
Browse files
Fixes: fakevim: work on writing
parent
2d67b9a0
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/plugins/fakevim/fakevimhandler.cpp
View file @
8b3136f8
...
...
@@ -1337,12 +1337,12 @@ int FakeVimHandler::Private::readLineCode(QString &cmd)
void
FakeVimHandler
::
Private
::
selectRange
(
int
beginLine
,
int
endLine
)
{
m_
tc
.
setPosition
(
positionForLine
(
beginLine
)
,
MoveAnchor
)
;
m_
anchor
=
positionForLine
(
beginLine
);
if
(
endLine
==
linesInDocument
())
{
m_tc
.
setPosition
(
positionForLine
(
endLine
),
Keep
Anchor
);
m_tc
.
movePosition
(
EndOfLine
,
Keep
Anchor
);
m_tc
.
setPosition
(
positionForLine
(
endLine
),
Move
Anchor
);
m_tc
.
movePosition
(
EndOfLine
,
Move
Anchor
);
}
else
{
m_tc
.
setPosition
(
positionForLine
(
endLine
+
1
),
Keep
Anchor
);
m_tc
.
setPosition
(
positionForLine
(
endLine
+
1
),
Move
Anchor
);
}
}
...
...
@@ -1400,29 +1400,33 @@ void FakeVimHandler::Private::handleExCommand(const QString &cmd0)
QString
fileName
=
reWrite
.
cap
(
2
);
if
(
fileName
.
isEmpty
())
fileName
=
m_currentFileName
;
QFile
file
(
fileName
);
bool
exists
=
file
.
exists
();
QFile
file
1
(
fileName
);
bool
exists
=
file
1
.
exists
();
if
(
exists
&&
!
forced
&&
!
noArgs
)
{
showRedMessage
(
tr
(
"File '%1' exists (add ! to override)"
).
arg
(
fileName
));
}
else
if
(
file
.
open
(
QIODevice
::
ReadWrite
))
{
file
.
close
();
QTextCursor
tc
=
m_tc
;
}
else
if
(
file1
.
open
(
QIODevice
::
ReadWrite
))
{
file1
.
close
();
selectRange
(
beginLine
,
endLine
);
QString
contents
=
selectedText
();
m_tc
=
tc
;
qDebug
()
<<
"LINES: "
<<
beginLine
<<
endLine
;
bool
handled
=
false
;
emit
q
->
writeFileRequested
(
&
handled
,
fileName
,
contents
);
// nobody cared, so act ourselves
if
(
!
handled
)
{
//qDebug() << "HANDLING MANUAL SAVE";
QFile
file
(
fileName
);
file
.
open
(
QIODevice
::
ReadWrite
);
{
QTextStream
ts
(
&
file
);
ts
<<
contents
;
}
file
.
close
();
//qDebug() << "HANDLING MANUAL SAVE TO " << fileName;
QFile
::
remove
(
fileName
);
QFile
file2
(
fileName
);
if
(
file2
.
open
(
QIODevice
::
ReadWrite
))
{
QTextStream
ts
(
&
file2
);
ts
<<
contents
;
}
else
{
showRedMessage
(
tr
(
"Cannot open file '%1' for writing"
).
arg
(
fileName
));
}
}
// check result by reading back
file
.
open
(
QIODevice
::
ReadOnly
);
QByteArray
ba
=
file
.
readAll
();
QFile
file3
(
fileName
);
file3
.
open
(
QIODevice
::
ReadOnly
);
QByteArray
ba
=
file3
.
readAll
();
showBlackMessage
(
tr
(
"
\"
%1
\"
%2 %3L, %4C written"
)
.
arg
(
fileName
).
arg
(
exists
?
" "
:
" [New] "
)
.
arg
(
ba
.
count
(
'\n'
)).
arg
(
ba
.
size
()));
...
...
@@ -1814,9 +1818,7 @@ QString FakeVimHandler::Private::selectedText() const
{
QTextCursor
tc
=
m_tc
;
tc
.
setPosition
(
m_anchor
,
KeepAnchor
);
QString
text
=
tc
.
selection
().
toPlainText
();
tc
.
clearSelection
();
return
text
;
return
tc
.
selection
().
toPlainText
();
}
int
FakeVimHandler
::
Private
::
positionForLine
(
int
line
)
const
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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