dbb9579566
When you are editing in a QTextEdit and press enter to start a new line, calling insertBlock() with no arguments tries to preserve the current charFormat and blockFormat. That is often OK: - if you hit enter at the end of a list item, you probably want another item in the same list - if you are writing code inside a code block, you're probably just writing the next statement on the next line: stay in the same block - margins, indents, tab positions should stay the same (but hopefully your editor has UI to manually reset the block format to default in case you are not continuing in the same style) But there are some exceptions we can apply to be helpful: - nobody ever wants to follow an <hr/> with another one (but hopefully the application has an action to insert one manually) - a heading is more likely to be followed by a paragraph, or perhaps a smaller heading; another heading at the same level is unlikely. We need to reset the char format, not only the block format, because the large font and heavy font weight are stored there. - when adding to a todo list, hitting enter at the end of the last task, let's assume the next task is not yet done, so it will be unchecked by default (else, why are you writing a todo list at all) To achieve that, we need to customize the formats and call the insertBlock() overload that takes them. The no-argument insertBlock() will continue to preserve the formats, because it's an old API that is used for much more than interactive editing. Additionally, word processors tend to let you end a list (for example) by hitting enter twice. In that case, you stay in the same paragraph that you created the first time you hit enter, but now the formats are reset to default, so that you can go on typing an ordinary paragraph, rather than having to mouse up to the toolbar to select the paragraph style in a combobox, or something like that. So we now do that: reset both block and char formats after you hit enter on a blank line; but if you then hit enter again, after the block format has been reset, then you will get the actual blank line (empty block) inserted. [ChangeLog][QtWidgets][QTextEdit] Hitting enter at the end of a line with a special block format (horizontal rule, heading, checklist item) now makes some "smart" adjustments to avoid retaining properties that are unlikely to be continued on the next line. Hitting enter twice now resets block and char formats to default. Fixes: QTBUG-48815 Task-number: QTBUG-80473 Fixes: QTBUG-97459 Change-Id: I3dfdd5b4c0d9ffb4673acc861cb7b5c22291df25 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> |
||
---|---|---|
.github/workflows | ||
bin | ||
cmake | ||
coin | ||
config.tests | ||
dist | ||
doc | ||
examples | ||
lib | ||
libexec | ||
mkspecs | ||
qmake | ||
src | ||
tests | ||
util | ||
.cmake.conf | ||
.gitattributes | ||
.gitignore | ||
.lgtm.yml | ||
.tag | ||
CMakeLists.txt | ||
conanfile.py | ||
config_help.txt | ||
configure | ||
configure.bat | ||
configure.cmake | ||
dependencies.yaml | ||
LICENSE.FDL | ||
LICENSE.GPL2 | ||
LICENSE.GPL3 | ||
LICENSE.GPL3-EXCEPT | ||
LICENSE.LGPL3 | ||
LICENSE.QT-LICENSE-AGREEMENT | ||
qt_cmdline.cmake | ||
sync.profile |