Go to file
Shawn Rutledge dbb9579566 Text editing: smart block and char format after newline
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>
2021-12-02 22:22:59 +01:00
.github/workflows Repair github action workflow 2021-11-10 18:57:33 +01:00
bin Provide a qtpaths wrapper script when cross-building Qt 2021-11-08 13:41:03 +01:00
cmake Install MSVC debug information for resource object libraries 2021-12-02 12:53:34 +01:00
coin Exclude INTEGRITY artifacts from Archivation step on CI 2021-12-02 20:09:40 +02:00
config.tests wasm: add simd support 2021-10-05 11:30:06 +10:00
dist Add Qt 6.0.0 changes file 2020-11-16 10:02:08 +02:00
doc Drop Qt3 support 2021-11-27 16:04:03 +03:00
examples Document the example showing the benefits of using bindable properties 2021-12-02 12:53:34 +01:00
lib Purge all fonts 2015-08-18 19:59:14 +00:00
libexec Fix various configure time warnings about missing QT_BEGIN_NAMESPACE 2021-11-01 17:17:29 +02:00
mkspecs android:qmake: Fix static libraries to include the QT_ARCH suffix 2021-12-02 20:29:58 +01:00
qmake Fix size_t / int conversion warnings in qmake 2021-12-02 15:16:49 +01:00
src Text editing: smart block and char format after newline 2021-12-02 22:22:59 +01:00
tests Text editing: smart block and char format after newline 2021-12-02 22:22:59 +01:00
util QLocale: Add support for Kaingang and Nheengatu languages 2021-11-10 00:36:12 +01:00
.cmake.conf Revert "CMake: Warn if cmake_minimum_required has an unsupported low version" 2021-10-04 15:55:10 +02:00
.gitattributes Give batch files CRLF line endings 2020-11-04 15:02:29 +00:00
.gitignore Assume qhelpgenerator in libexec instead of bin 2021-11-08 19:27:32 +01:00
.lgtm.yml Skip LGTM analysis for the bootstrap library and tools 2020-07-16 01:04:34 +02:00
.tag Update the git-archive export options 2012-09-07 15:39:31 +02:00
CMakeLists.txt Add _make_aab target 2021-11-30 20:16:13 +01:00
conanfile.py Conan: Do not write qt.conf to build artifacts 2021-11-30 17:34:00 +02:00
config_help.txt Document that schannel is on by default 2021-10-06 15:05:20 +02:00
configure Remove unsupported, host-related options from configure shell script 2021-08-05 02:44:27 +02:00
configure.bat Fix our usage of CMake script mode in Windows configure 2021-08-20 19:44:43 +02:00
configure.cmake wasm: add simd support 2021-10-05 11:30:06 +10:00
dependencies.yaml Re-add dependencies.yaml now that qt5.git wip/qt6 builds fine 2019-09-18 13:19:31 +02:00
LICENSE.FDL Remove trailing whitespace in LICENSE.FDL 2021-11-26 18:28:49 +01:00
LICENSE.GPL2 Add new license header templates and license files 2016-01-14 20:43:46 +00:00
LICENSE.GPL3 Add new license header templates and license files 2016-01-14 20:43:46 +00:00
LICENSE.GPL3-EXCEPT Add new license header templates and license files 2016-01-14 20:43:46 +00:00
LICENSE.LGPL3 Add new license header templates and license files 2016-01-14 20:43:46 +00:00
LICENSE.QT-LICENSE-AGREEMENT Update latest qt license agreement 2021-12-02 14:16:49 +00:00
qt_cmdline.cmake configure: Remove vestiges of handling QMAKE_* variable assignments 2021-11-24 10:47:10 +01:00
sync.profile Implement generating of a module cpp export header 2021-06-24 20:40:49 +02:00