Disable code line number in code block by default

pull/1471/head
Ahmed Hnewa 2 years ago
parent 8149e2b2d1
commit a89949a9d5
No known key found for this signature in database
GPG Key ID: C488CC70BBCEF0D1
  1. 3
      CHANGELOG.md
  2. 19
      lib/src/models/config/editor/block_options.dart
  3. 18
      lib/src/models/config/editor/blocks/code_block.dart
  4. 15
      lib/src/models/config/editor/configurations.dart
  5. 30
      lib/src/utils/extensions/build_context.dart
  6. 5
      lib/src/widgets/text_block.dart
  7. 2
      pubspec.yaml

@ -1,3 +1,6 @@
## [7.10.2]
- Removing line numbers from code block by default, you still can enable this thanks to the new configurations in the `QuillEditor` you will find a `blockOptions` property, in it you will find the code which mean code block options. just pass true to `enableLineNumbers`
## [7.10.1]
- Fixes and use the new parameters
- You don't need to use MaterialApp anymore to use most of the toolbar buttons childBuilder anymore

@ -0,0 +1,19 @@
import 'package:equatable/equatable.dart';
import 'package:flutter/foundation.dart' show immutable;
import 'blocks/code_block.dart';
export 'blocks/code_block.dart';
@immutable
class QuillEditorBlockOptions extends Equatable {
const QuillEditorBlockOptions({
this.code = const QuillEditorCodeBlockOptions(),
});
final QuillEditorCodeBlockOptions code;
@override
List<Object?> get props => [
code,
];
}

@ -0,0 +1,18 @@
import 'package:equatable/equatable.dart';
import 'package:flutter/foundation.dart' show immutable;
@immutable
class QuillEditorCodeBlockOptions extends Equatable {
const QuillEditorCodeBlockOptions({
this.enableLineNumbers = false,
});
/// If you want line numbers in the code block, please pass true
/// by default it's false as it's not really needed in most cases
final bool enableLineNumbers;
@override
List<Object?> get props => [
enableLineNumbers,
];
}

@ -1,4 +1,3 @@
// ignore_for_file: public_member_api_docs, sort_constructors_first
import 'package:equatable/equatable.dart';
import 'package:flutter/foundation.dart' show Brightness, Uint8List, immutable;
import 'package:flutter/material.dart'
@ -12,6 +11,9 @@ import '../../../widgets/embeds.dart';
import '../../../widgets/link.dart';
import '../../../widgets/raw_editor/raw_editor.dart';
import '../../themes/quill_dialog_theme.dart';
import 'block_options.dart';
export 'block_options.dart';
/// The configurations for the quill editor widget of flutter quill
@immutable
@ -62,6 +64,7 @@ class QuillEditorConfigurations extends Equatable {
this.contextMenuBuilder,
this.editorKey,
this.requestKeyboardFocusOnCheckListChanged = false,
this.blockOptions = const QuillEditorBlockOptions(),
});
/// The text placeholder in the quill editor
@ -289,6 +292,9 @@ class QuillEditorConfigurations extends Equatable {
/// should we request keyboard focus??
final bool requestKeyboardFocusOnCheckListChanged;
/// This is not complete yet and might changed
final QuillEditorBlockOptions blockOptions;
@override
List<Object?> get props => [
placeholder,
@ -298,6 +304,7 @@ class QuillEditorConfigurations extends Equatable {
// We might use code generator like freezed but sometimes it can be limitied
// instead whatever there is a change to the parameters in this class please
// regenerate this function using extension in vs code or plugin in intellij
QuillEditorConfigurations copyWith({
String? placeholder,
bool? readOnly,
@ -336,6 +343,8 @@ class QuillEditorConfigurations extends Equatable {
ContentInsertionConfiguration? contentInsertionConfiguration,
GlobalKey<EditorState>? editorKey,
TextSelectionThemeData? textSelectionThemeData,
bool? requestKeyboardFocusOnCheckListChanged,
QuillEditorBlockOptions? blocksOptions,
}) {
return QuillEditorConfigurations(
placeholder: placeholder ?? this.placeholder,
@ -384,6 +393,10 @@ class QuillEditorConfigurations extends Equatable {
editorKey: editorKey ?? this.editorKey,
textSelectionThemeData:
textSelectionThemeData ?? this.textSelectionThemeData,
requestKeyboardFocusOnCheckListChanged:
requestKeyboardFocusOnCheckListChanged ??
this.requestKeyboardFocusOnCheckListChanged,
blockOptions: blocksOptions ?? this.blockOptions,
);
}
}

@ -2,6 +2,8 @@ import 'package:flutter/widgets.dart' show BuildContext;
import '../../../flutter_quill.dart';
// TODO: The documentation of this file needs to be updated as it's quite oudated.
/// Public shared extension
extension BuildContextExt on BuildContext {
/// return [QuillProvider] as not null
@ -67,7 +69,8 @@ extension BuildContextExt on BuildContext {
}
/// return [QuillEditorConfigurations] as not null . Since the quill
/// editor configurations is in the [QuillProvider] then we need to get the
/// editor configurations is in the [QuillEditorProvider]
/// then we need to get the
/// provider widget first and then we will return editor configurations
/// throw exception if [QuillProvider] is not in the widget tree
QuillEditorConfigurations get requireQuillEditorConfigurations {
@ -75,7 +78,8 @@ extension BuildContextExt on BuildContext {
}
/// return nullable [QuillEditorConfigurations]. Since the quill
/// editor configurations is in the [QuillProvider] then we need to get the
/// editor configurations is in the [QuillEditorProvider]
/// then we need to get the
/// provider widget first and then we will return editor configurations
/// don't throw exception if [QuillProvider] is not in the widget tree
QuillEditorConfigurations? get quillEditorConfigurations {
@ -83,7 +87,8 @@ extension BuildContextExt on BuildContext {
}
/// return [QuillToolbarConfigurations] as not null . Since the quill
/// toolbar configurations is in the [QuillProvider] then we need to get the
/// toolbar configurations is in the [QuillToolbarProvider]
/// then we need to get the
/// provider widget first and then we will return toolbar configurations
/// throw exception if [QuillProvider] is not in the widget tree
QuillToolbarConfigurations get requireQuillToolbarConfigurations {
@ -91,7 +96,8 @@ extension BuildContextExt on BuildContext {
}
/// return nullable [QuillToolbarConfigurations]. Since the quill
/// toolbar configurations is in the [QuillProvider] then we need to get the
/// toolbar configurations is in the [QuillToolbarProvider]
/// then we need to get the
/// provider widget first and then we will return toolbar configurations
/// don't throw exception if [QuillProvider] is not in the widget tree
QuillToolbarConfigurations? get quillToolbarConfigurations {
@ -113,4 +119,20 @@ extension BuildContextExt on BuildContext {
QuillToolbarBaseButtonOptions get requireQuillToolbarBaseButtonOptions {
return requireQuillToolbarConfigurations.buttonOptions.base;
}
/// return nullable [QuillToolbarBaseButtonOptions]. Since the quill
/// quill editor block options is in the [QuillEditorProvider] then we need to
/// get the provider widget first and then we will return block options
/// throw exception if [QuillEditorProvider] is not in the widget tree
QuillEditorBlockOptions? get quillEditorBlockOptions {
return quillEditorConfigurations?.blockOptions;
}
/// return [QuillToolbarBaseButtonOptions] as not null. Since the quill
/// quill editor block options is in the [QuillEditorProvider] then we need to
/// get the provider widget first and then we will return block options
/// don't throw exception if [QuillEditorProvider] is not in the widget tree
QuillEditorBlockOptions get requireQuillEditorBlockOptions {
return requireQuillEditorConfigurations.blockOptions;
}
}

@ -6,6 +6,7 @@ import '../models/documents/nodes/block.dart';
import '../models/documents/nodes/line.dart';
import '../models/structs/vertical_spacing.dart';
import '../utils/delta.dart';
import '../utils/extensions/build_context.dart';
import 'box.dart';
import 'controller.dart';
import 'cursor.dart';
@ -230,8 +231,8 @@ class EditableTextBlock extends StatelessWidget {
uiBuilder: defaultStyles.lists?.checkboxUIBuilder,
);
}
if (attrs.containsKey(Attribute.codeBlock.key)) {
if (attrs.containsKey(Attribute.codeBlock.key) &&
context.requireQuillEditorBlockOptions.code.enableLineNumbers) {
return QuillNumberPoint(
index: index,
indentLevelCounts: indentLevelCounts,

@ -1,6 +1,6 @@
name: flutter_quill
description: A rich text editor built for the modern Android, iOS, web and desktop platforms. It is the WYSIWYG editor and a Quill component for Flutter.
version: 7.10.1
version: 7.10.2
homepage: https://1o24bbs.com/c/bulletjournal/108
repository: https://github.com/singerdmx/flutter-quill
topics:

Loading…
Cancel
Save