Pythonista-Issues icon indicating copy to clipboard operation
Pythonista-Issues copied to clipboard

Almost impossible to copy text from the console.(Continued bug from pythonista 3.3 to the current 3.4 beta)

Open watosar opened this issue 2 years ago • 2 comments
trafficstars

This bug occurs in both the editor and console screens. After being in edit mode, where the keyboard is visible, switching to non-edit mode allows the user to scroll the text on the screen until it disappears completely from the screen. At the same time, it becomes difficult to select and copy text in non-editable text (output to the console or non-editable files). This is because when you touch the screen to select text, the text scrolls up by itself.

pythonista 340006 iPhone 6s plus ios 15.7.2 iPhone se gen2 ios 16.2

watosar avatar Jan 18 '23 13:01 watosar

Please add Pythonista 3.4 beta to the issue title above.

cclauss avatar Jan 18 '23 13:01 cclauss

For those who suffer from the same bug and can't wait for the update. I have written a script to alleviate the symptoms of this bug and will share it with you.

  1. add https://github.com/jsbain/objc_hacks/blob/master/swizzle.py to site-packages
  2. add the following code to site-packages/pythonista_startup.py
from objc_util import *
import swizzling
import editor

win = UIApplication.sharedApplication().keyWindow()
root_vc = win.rootViewController()
console_vc = root_vc.accessoryViewController().consoleViewController()

def consoleAdjustInsetsForKeyboardFrameChangeNotification_(_self, _cmd, ptr,*, ObjCInstance=ObjCInstance, UIEdgeInsets=UIEdgeInsets):
    obj=ObjCInstance(_self)
    arg = ObjCInstance(ptr)
    
    keyheight = arg.userInfo()['UIKeyboardFrameEndUserInfoKey'].rectValue().size.height
    keyboardon = keyheight>0
    obj.consoleOutputTextView().setContentInset_(
        UIEdgeInsets(0,0,(keyheight+32)*keyboardon,0))
        
def adjustInsetsForKeyboardFrameChangeNotification_(_self, _cmd, ptr,*,ObjCInstance=ObjCInstance, UIEdgeInsets=UIEdgeInsets, ObjCClass=ObjCClass): 
    obj=ObjCInstance(_self)
    arg = ObjCInstance(ptr)
    
    obj.originaladjustInsetsForKeyboardFrameChangeNotification_(arg) 
    if obj.delegate().isKindOfClass_(ObjCClass('PA2ConsoleViewController')):
        return 
    
    keyheight = arg.userInfo()['UIKeyboardFrameEndUserInfoKey'].rectValue().size.height
    keyboardon = keyheight>0
    obj.textView().setContentInset_(
        UIEdgeInsets(0,0,(keyheight+32)*keyboardon,0))

swizzling.swizzle(
    ObjCInstance(ObjCClass('PA2ConsoleViewController').ptr), 
    'adjustInsetsForKeyboardFrameChangeNotification:', 
    consoleAdjustInsetsForKeyboardFrameChangeNotification_)
swizzling.swizzle(
    ObjCInstance(ObjCClass('OMTextEditorView').ptr),
    'adjustInsetsForKeyboardFrameChangeNotification:',
    adjustInsetsForKeyboardFrameChangeNotification_)

watosar avatar Feb 01 '23 09:02 watosar