Paste a Method (Function)

This was discussed recently, and I had to do just that today.

I recall to need to press the Option key (long time ago), but I do not checked that…

I add a Method, press Cmd-P: nothing.

I selected (green background) the Method and press Cmd.P: the method was added, completely, functional.

I checked the above statement and yes this works fine.

I also tried to select that newly added Method and press Cmd-P with a different Method in the Clipboard: this does not works.

NB: I do not checked to Paste a Function.

Xojo 2025r3.1
MacOS Tahoe (a)
MacBook Pro 13" M1.

Paste-as-a-function only works if the code on the clipboard is properly formatted, which isn’t the easiest thing to do. Copying code from unknown sources or AI usually fails to paste as a function.

There is an issues ticket for this:
#79703 - Make Xojo smarter when pasting code from ChatGPT (or any other LLM)

I cannot talk about AI, but the Function below can be pasted:

  Return A.ToString
End Function

So, it is easy to create one: I just did it !$Yes, this one is useless except for the demonstration.

To be sure, add a new Function with needed parameters / Return Type and populate the code area.
Then, Select your Function, Copy it, Delete it, Select the Module Name in the Navigator Pane and Cmd-P: it works fine here.

Now, I read the Issue and try to understand the “Problem” (to know if in that case, I am wrong)

About the Example 2:
Where is the Return Line ?

The Method below can be Pasted in a Module:
Public Sub ComputeXXXFromCloses(closes() As Double, fastPeriod As Integer, slowPeriod As Integer, signalPeriod As Integer, ByRef signal() As Double, ByRef hist() As Double)

Var n As Integer = closes.Count
macd.ResizeTo(n - 1)
signal.ResizeTo(n - 1)
hist.ResizeTo(n - 1)

//Do something more

End Sub

And the Function below can be Pasted:

Public Function ComputeXXXFromCloses(closes() As Double, fastPeriod As Integer, slowPeriod As Integer, signalPeriod As Integer, ByRef signal() As Double, ByRef hist() As Double) As Integer
  
  Var n As Integer = closes.Count
  macd.ResizeTo(n - 1)
  signal.ResizeTo(n - 1)
  hist.ResizeTo(n - 1)
  
  //Do something more
  
  Return n
  
  
End Function

I only add the line: Return n to the original code.

Conclusion: I do not understand what the problem is.

Care to explain, so I can understand ?