Skip to content

Commit

Permalink
IOS-2990 Delete code
Browse files Browse the repository at this point in the history
  • Loading branch information
mgolovko committed Aug 5, 2024
1 parent 9f71764 commit 47e2f63
Show file tree
Hide file tree
Showing 9 changed files with 1 addition and 205 deletions.
4 changes: 0 additions & 4 deletions Anytype.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1619,7 +1619,6 @@
C9121A5E273B918900FFDA07 /* BlocksSelectionOverlayViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9121A5D273B918900FFDA07 /* BlocksSelectionOverlayViewModel.swift */; };
C91989ED2811673600CC6BEB /* UndoRedoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C91989EC2811673600CC6BEB /* UndoRedoView.swift */; };
C91AFF11270C3E2F005F9386 /* ActivityViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C91AFF10270C3E2F005F9386 /* ActivityViewController.swift */; };
C91B81BA28E74222006AE9EB /* AnytypeWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = C91B81B928E74222006AE9EB /* AnytypeWindow.swift */; };
C91FAF5D2812865B0055BC4A /* UndoRedoViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C91FAF5C2812865B0055BC4A /* UndoRedoViewModel.swift */; };
C91FAF5F2812C2510055BC4A /* AlertModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C91FAF5E2812C2510055BC4A /* AlertModel.swift */; };
C920F7F92903082600360F01 /* BlockTextLinkView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C920F7F82903082600360F01 /* BlockTextLinkView.swift */; };
Expand Down Expand Up @@ -3486,7 +3485,6 @@
C9121A5D273B918900FFDA07 /* BlocksSelectionOverlayViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlocksSelectionOverlayViewModel.swift; sourceTree = "<group>"; };
C91989EC2811673600CC6BEB /* UndoRedoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UndoRedoView.swift; sourceTree = "<group>"; };
C91AFF10270C3E2F005F9386 /* ActivityViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActivityViewController.swift; sourceTree = "<group>"; };
C91B81B928E74222006AE9EB /* AnytypeWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnytypeWindow.swift; sourceTree = "<group>"; };
C91FAF5C2812865B0055BC4A /* UndoRedoViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UndoRedoViewModel.swift; sourceTree = "<group>"; };
C91FAF5E2812C2510055BC4A /* AlertModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertModel.swift; sourceTree = "<group>"; };
C920F7F82903082600360F01 /* BlockTextLinkView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlockTextLinkView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -5272,7 +5270,6 @@
isa = PBXGroup;
children = (
0303ED0022D8EDAA005C552B /* SceneDelegate.swift */,
C91B81B928E74222006AE9EB /* AnytypeWindow.swift */,
);
path = SceneDelegates;
sourceTree = "<group>";
Expand Down Expand Up @@ -12266,7 +12263,6 @@
3DE0CFCD26F8591E003A606A /* SlashMenuCellData.swift in Sources */,
2AEAA48729F6A3D6009ACA00 /* ColorsExample.swift in Sources */,
C9E9F5E427FC7E7F008163D9 /* InsetConstraints.swift in Sources */,
C91B81BA28E74222006AE9EB /* AnytypeWindow.swift in Sources */,
C9892C3D284E22E2006E3BE3 /* SpreadsheetLayout.swift in Sources */,
2E975EF0287C23DA004DE574 /* SetSortsListViewModel.swift in Sources */,
2A82AB382B9754CB00AA8E18 /* ServicesDI.swift in Sources */,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@

import Services
import UIKit

struct TextViewSelectionPosition: OptionSet {
var rawValue: UInt8

static let none = TextViewSelectionPosition([])
static let start = TextViewSelectionPosition(rawValue: 0x01)
static let middle = TextViewSelectionPosition(rawValue: 0x02)
static let end = TextViewSelectionPosition(rawValue: 0x04)
}

extension UITextView {
var isCarretInTheBeginingOfDocument: Bool {
guard let caretPosition = caretPosition else {
Expand All @@ -25,22 +15,6 @@ extension UITextView {
let offset = selectedRange.location + selectedRange.length
return position(from: beginningOfDocument, offset: offset)
}

var textViewSelectionPosition: TextViewSelectionPosition {
guard selectedRange.length > 0 else { return .none }

var position = TextViewSelectionPosition.middle

if selectedRange.location == 0 {
position.insert(.start)
}

if selectedRange.contains(text.count - 1) {
position.insert(.end)
}

return position
}

/// Append plain string to attributed string after caret.
/// If attributedText is empty, `typingAttributes` will be set to default.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,6 @@ final class TextBlockActionHandler: TextBlockActionHandlerProtocol {
accessoryViewStateManager.selectionDidChange(range: range)
cursorManager.blockFocus = BlockFocus(id: info.id, position: .at(range))
// cursorManager.didChangeCursorPosition(at: data.info.id, position: .at(range)) // DO WE NEED IT? WHY?
collectionController.didSelectTextRangeSelection(blockId: info.id, textView: textView)
}

private func toggleCheckBox() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ protocol EditorPageSelectionManagerProtocol {
func canSelectBlock(at indexPath: IndexPath) -> Bool
func didLongTap(at indexPath: IndexPath)
func didUpdateSelectedIndexPaths(_ indexPaths: [IndexPath])

// MARK: - Optional
func didSelectSelection(from indexPath: IndexPath)}

extension EditorPageSelectionManagerProtocol {
func didSelectSelection(from indexPath: IndexPath) {}
}

@MainActor
Expand Down Expand Up @@ -496,14 +490,7 @@ extension EditorPageBlocksStateManager: SimpleTableSelectionHandler {
}

extension EditorPageBlocksStateManager {
func didSelectSelection(from indexPath: IndexPath) {
guard let blockViewModel = modelsHolder.blockViewModel(at: indexPath.row) else { return }

editingState = .selecting(blocks: [blockViewModel.info.id])
selectedBlocks = [blockViewModel.info.id]
updateSelectionBarActions(selectedBlocks: [blockViewModel.info])
}


func didSelectEditingState(info: BlockInformation) {
editingState = .selecting(blocks: [info.id])
selectedBlocks = [info.id]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ final class EditorPageController: UIViewController {
layout.layoutDetailsPublisher = viewModel.document.layoutDetailsPublisher.receiveOnMain().eraseToAnyPublisher()
}
}

private var selectingRangeEditorItem: EditorItem?
private var selectingRangeTextView: UITextView?

private var cancellables = [AnyCancellable]()
private var applyAnimationConfig = false
Expand Down Expand Up @@ -127,76 +124,6 @@ final class EditorPageController: UIViewController {
collectionView.allowsSelectionDuringEditing = true

navigationBarHelper.handleViewWillAppear(scrollView: collectionView)

AnytypeWindow.shared?.textRangeTouchSubject.sink { [weak self] touch in
self?.handleTextSelectionTouch(touch)
}.store(in: &cancellables)
}


private func performBlocksSelection(with touch: UITouch) {
guard let indexPath = collectionView.indexPath(for: touch) else {
return
}

selectItem(at: indexPath)
}

private func selectItem(at indexPath: IndexPath, animated: Bool = true) {
guard viewModel.blocksStateManager.canSelectBlock(at: indexPath) else {
return
}

if collectionView.indexPathsForSelectedItems?.contains(indexPath) ?? false {
return
}

collectionView.selectItem(at: indexPath, animated: true, scrollPosition: [])
collectionView.indexPathsForSelectedItems.map {
viewModel.blocksStateManager.didUpdateSelectedIndexPaths($0)
}
}

private func handleTextSelectionTouch(_ touch: UITouch) {
switch viewModel.blocksStateManager.editingState {
case .selecting:
performBlocksSelection(with: touch)
case .editing:
guard let selectingRangeEditorItem = selectingRangeEditorItem,
selectingRangeEditorItem.canHandleTextRangeTouch,
let sourceTextIndexPath = dataSource.indexPath(for: selectingRangeEditorItem),
let cell = collectionView.cellForItem(at: sourceTextIndexPath) else {
return
}
let pointInCell = touch.location(in: cell)
let isAscendingTouch = pointInCell.y > cell.center.y
let threshold: CGFloat = isAscendingTouch ? Constants.selectingTextThreshold : -Constants.selectingTextThreshold
var locationInCollectionView = touch.location(in: collectionView)

locationInCollectionView.y = locationInCollectionView.y + threshold

guard let touchingIndexPath = collectionView.indexPathForItem(at: locationInCollectionView),
let touchingItem = dataSource.itemIdentifier(for: touchingIndexPath),
touchingItem != selectingRangeEditorItem,
let selectingRangeTextView = selectingRangeTextView,
let sourceTextIndexPath = dataSource.indexPath(for: selectingRangeEditorItem)
else {
return
}

let isValidForDescending = selectingRangeTextView.textViewSelectionPosition.contains(.start) &&
sourceTextIndexPath.compare(touchingIndexPath) == .orderedDescending

let isValidForAscending = selectingRangeTextView.textViewSelectionPosition.contains(.end) &&
sourceTextIndexPath.compare(touchingIndexPath) == .orderedAscending

if isValidForAscending || isValidForDescending {
UIApplication.shared.hideKeyboard()
viewModel.blocksStateManager.didSelectSelection(from: sourceTextIndexPath)
selectItem(at: touchingIndexPath)
}
default: break
}
}

override func viewWillAppear(_ animated: Bool) {
Expand Down Expand Up @@ -345,13 +272,6 @@ extension EditorPageController: EditorPageViewInput {
navigationBarHelper.updateSyncStatusData(syncStatusData)
}

func didSelectTextRangeSelection(blockId: String, textView: UITextView) {
if let item = dataSourceItem(for: blockId), textView.textViewSelectionPosition.contains(.end) || textView.textViewSelectionPosition.contains(.start) {
self.selectingRangeEditorItem = item
self.selectingRangeTextView = textView
}
}

func reconfigure(items: [EditorItem]) {
guard items.count > 0 else { return }

Expand Down Expand Up @@ -422,8 +342,6 @@ extension EditorPageController: EditorPageViewInput {

func blockDidFinishEditing() {
self.firstResponderView = nil
self.selectingRangeTextView = nil
self.selectingRangeEditorItem = nil
}

// MARK: -
Expand Down Expand Up @@ -659,16 +577,7 @@ private extension EditorPageController {
}
}

extension UICollectionView {
func indexPath(for touch: UITouch) -> IndexPath? {
let point = touch.location(in: self)

return indexPathForItem(at: point)
}
}

private enum Constants {
static let selectingTextThreshold: CGFloat = 30
static let shakeUndoTriggerDuration: CGFloat = 1
}

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ protocol EditorCollectionReloadable: AnyObject {
func textBlockDidBeginEditing(firstResponderView: UIView)
func textBlockWillBeginEditing()
func blockDidFinishEditing()
func didSelectTextRangeSelection(blockId: String, textView: UITextView)
}

/// Input data for document view
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,4 @@ final class EditorBlockCollectionController: EditorCollectionReloadable {
func blockDidFinishEditing() {
viewInput?.blockDidFinishEditing()
}

func didSelectTextRangeSelection(blockId: String, textView: UITextView) {
viewInput?.didSelectTextRangeSelection(blockId: blockId, textView: textView)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,3 @@ extension EditorItem {
}
}

extension EditorItem {
var canHandleTextRangeTouch: Bool {
switch self {
case .header:
return false
case .block(let viewModel):
return viewModel.info.content.type != .text(.title)
case .system:
return true
}
}
}

0 comments on commit 47e2f63

Please sign in to comment.