You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
3.7 KiB

5 years ago
  1. //
  2. // SlackTextViewController
  3. // https://github.com/slackhq/SlackTextViewController
  4. //
  5. // Copyright 2014-2016 Slack Technologies, Inc.
  6. // Licence: MIT-Licence
  7. //
  8. #import "SLKTextView.h"
  9. NS_ASSUME_NONNULL_BEGIN
  10. /** @name SLKTextView additional features used for SlackTextViewController. */
  11. @interface SLKTextView (SLKAdditions)
  12. /**
  13. Clears the text.
  14. @param clearUndo YES if clearing the text should also clear the undo manager (if enabled).
  15. */
  16. - (void)slk_clearText:(BOOL)clearUndo;
  17. /**
  18. Scrolls to the very end of the content size, animated.
  19. @param animated YES if the scrolling should be animated.
  20. */
  21. - (void)slk_scrollToBottomAnimated:(BOOL)animated;
  22. /**
  23. Scrolls to the caret position, animated.
  24. @param animated YES if the scrolling should be animated.
  25. */
  26. - (void)slk_scrollToCaretPositonAnimated:(BOOL)animated;
  27. /**
  28. Inserts a line break at the caret's position.
  29. */
  30. - (void)slk_insertNewLineBreak;
  31. /**
  32. Inserts a string at the caret's position.
  33. @param text The string to be appended to the current text.
  34. */
  35. - (void)slk_insertTextAtCaretRange:(NSString *)text;
  36. /**
  37. Insert a string at the caret's position with stylization from the attributes.
  38. @param text The string to be appended to the current text.
  39. @param attributes The attributes used to stylize the text.
  40. */
  41. - (void)slk_insertTextAtCaretRange:(NSString *)text
  42. withAttributes:(NSDictionary<NSString *, id> *)attributes;
  43. /**
  44. Adds a string to a specific range.
  45. @param text The string to be appended to the current text.
  46. @param range The range where to insert text.
  47. @return The range of the newly inserted text.
  48. */
  49. - (NSRange)slk_insertText:(NSString *)text inRange:(NSRange)range;
  50. /**
  51. Adds a string to a specific range, with stylization from the attributes.
  52. @param text The string to be appended to the current text.
  53. @param attributes The attributes used to stylize the text.
  54. @param range The range where to insert text.
  55. @return The range of the newly inserted text.
  56. */
  57. - (NSRange)slk_insertText:(NSString *)text
  58. withAttributes:(NSDictionary<NSString *, id> *)attributes
  59. inRange:(NSRange)range;
  60. /**
  61. Sets the text attributes for the attributed string in the provided range.
  62. @param attributes The attributes used to style NSAttributedString class.
  63. @param range The range of the text that needs to be stylized by the given attributes.
  64. @return An attributed string.
  65. */
  66. - (NSAttributedString *)slk_setAttributes:(NSDictionary<NSString *, id> *)attributes
  67. inRange:(NSRange)range;
  68. /**
  69. Inserts an attributed string at the caret's position.
  70. @param attributedText The attributed string to be appended.
  71. */
  72. - (void)slk_insertAttributedTextAtCaretRange:(NSAttributedString *)attributedText;
  73. /**
  74. Adds an attributed string to a specific range.
  75. @param attributedText The string to be appended to the current text.
  76. @param range The range where to insert text.
  77. @return The range of the newly inserted text.
  78. */
  79. - (NSRange)slk_insertAttributedText:(NSAttributedString *)attributedText inRange:(NSRange)range;
  80. /**
  81. Removes all attributed string attributes from the text view, for the given range.
  82. @param range The range to remove the attributes.
  83. */
  84. - (void)slk_clearAllAttributesInRange:(NSRange)range;
  85. /**
  86. Returns a default attributed string, using the text view's font and text color.
  87. @param text The string to be used for creating a new attributed string.
  88. @return An attributed string.
  89. */
  90. - (NSAttributedString *)slk_defaultAttributedStringForText:(NSString *)text;
  91. /**
  92. Registers the current text for future undo actions.
  93. @param description A simple description associated with the Undo or Redo command.
  94. */
  95. - (void)slk_prepareForUndo:(NSString *)description;
  96. @end
  97. NS_ASSUME_NONNULL_END